// ==UserScript==
// @name Dinzer Lite
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Protect Your Website!
// @author You
// @match *://*/*
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
// Thanks For Using Our App! We would update it frenquently!!
(function() {
'use strict';
const settings = {
adBlocker: GM_getValue('adBlocker', true),
popupBlocker: GM_getValue('popupBlocker', true),
darkMode: GM_getValue('darkMode', false),
speedBoost: GM_getValue('speedBoost', true)
};
function saveSettings() {
for (const key in settings) {
GM_setValue(key, settings[key]);
}
}
function blockAds() {
if (!settings.adBlocker) return;
const adSelectors = [
'div[id*="banner"]',
'div[id*="ad-"]',
'div[class*="ad-"]',
'div[class*="ads"]',
'div[id*="ads"]',
'iframe[src*="doubleclick"]',
'iframe[src*="ads"]',
'.adsbygoogle'
];
function hideAds() {
adSelectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
elements.forEach(el => {
el.style.display = 'none';
});
});
}
hideAds();
const observer = new MutationObserver(hideAds);
observer.observe(document.body, { childList: true, subtree: true });
}
function blockPopups() {
if (!settings.popupBlocker) return;
const originalOpen = window.open;
window.open = function() {
if (arguments[1] && arguments[1].includes('_blank')) {
arguments[1] = '_self';
}
return originalOpen.apply(this, arguments);
};
function processLinks() {
document.querySelectorAll('a[target="_blank"]').forEach(link => {
link.setAttribute('target', '_self');
});
}
processLinks();
const observer = new MutationObserver(processLinks);
observer.observe(document.body, { childList: true, subtree: true });
}
function applyDarkMode() {
if (!settings.darkMode) {
if (document.getElementById('webProtectorDarkMode')) {
document.getElementById('webProtectorDarkMode').disabled = true;
}
return;
}
const darkModeCSS = `
body {
background-color: #222 !important;
color: #ddd !important;
}
a {
color: #6bf !important;
}
input, textarea, select {
background-color: #333 !important;
color: #ddd !important;
border-color: #555 !important;
}
div, p, span, h1, h2, h3, h4, h5, h6 {
color: #ddd !important;
}
`;
if (!document.getElementById('webProtectorDarkMode')) {
const style = document.createElement('style');
style.id = 'webProtectorDarkMode';
style.textContent = darkModeCSS;
document.head.appendChild(style);
} else {
document.getElementById('webProtectorDarkMode').disabled = false;
}
}
function applySpeedBoost() {
if (!settings.speedBoost) return;
document.querySelectorAll('img').forEach(img => {
if (img.loading === 'lazy' && isElementInViewport(img)) {
img.loading = 'eager';
}
if (img.getAttribute('data-src') && isElementInViewport(img)) {
img.src = img.getAttribute('data-src');
}
});
document.querySelectorAll('iframe:not([src*="youtube"]):not([src*="vimeo"])').forEach(iframe => {
if (!isElementInViewport(iframe)) {
iframe.setAttribute('data-src', iframe.src);
iframe.removeAttribute('src');
}
});
}
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function createUI() {
const container = document.createElement('div');
container.id = 'webProtectorUI';
GM_addStyle(`
#webProtectorUI {
position: fixed;
left: 20px;
bottom: 20px;
background: rgba(40, 44, 52, 0.9);
color: white;
padding: 10px;
border-radius: 8px;
font-family: Arial, sans-serif;
z-index: 9999;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
width: 200px;
transition: all 0.3s ease;
font-size: 14px;
}
#webProtectorUI.collapsed {
width: auto;
height: auto;
}
#webProtectorUI .header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
cursor: move;
}
#webProtectorUI .toggle-btn {
cursor: pointer;
user-select: none;
}
#webProtectorUI .options {
display: flex;
flex-direction: column;
gap: 8px;
}
#webProtectorUI .option {
display: flex;
justify-content: space-between;
align-items: center;
}
#webProtectorUI .switch {
position: relative;
display: inline-block;
width: 40px;
height: 20px;
}
#webProtectorUI .switch input {
opacity: 0;
width: 0;
height: 0;
}
#webProtectorUI .slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .3s;
border-radius: 20px;
}
#webProtectorUI .slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 2px;
bottom: 2px;
background-color: white;
transition: .3s;
border-radius: 50%;
}
#webProtectorUI input:checked + .slider {
background-color: #4cd964;
}
#webProtectorUI input:checked + .slider:before {
transform: translateX(20px);
}
`);
container.innerHTML = `
<div class="header">
<span>Web Protector</span>
<span class="toggle-btn">➖</span>
</div>
<div class="options">
<div class="option">
<span>Chặn quảng cáo</span>
<label class="switch">
<input type="checkbox" id="adBlocker" ${settings.adBlocker ? 'checked' : ''}>
<span class="slider"></span>
</label>
</div>
<div class="option">
<span>Chặn popup</span>
<label class="switch">
<input type="checkbox" id="popupBlocker" ${settings.popupBlocker ? 'checked' : ''}>
<span class="slider"></span>
</label>
</div>
<div class="option">
<span>Chế độ tối</span>
<label class="switch">
<input type="checkbox" id="darkMode" ${settings.darkMode ? 'checked' : ''}>
<span class="slider"></span>
</label>
</div>
<div class="option">
<span>Tăng tốc trang</span>
<label class="switch">
<input type="checkbox" id="speedBoost" ${settings.speedBoost ? 'checked' : ''}>
<span class="slider"></span>
</label>
</div>
</div>
`;
document.body.appendChild(container);
const toggleBtn = container.querySelector('.toggle-btn');
const options = container.querySelector('.options');
let isCollapsed = false;
toggleBtn.addEventListener('click', () => {
isCollapsed = !isCollapsed;
if (isCollapsed) {
options.style.display = 'none';
toggleBtn.textContent = '➕';
container.classList.add('collapsed');
} else {
options.style.display = 'flex';
toggleBtn.textContent = '➖';
container.classList.remove('collapsed');
}
});
container.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
checkbox.addEventListener('change', function() {
settings[this.id] = this.checked;
saveSettings();
if (this.id === 'adBlocker') blockAds();
if (this.id === 'popupBlocker') blockPopups();
if (this.id === 'darkMode') applyDarkMode();
if (this.id === 'speedBoost') applySpeedBoost();
});
});
makeElementDraggable(container, container.querySelector('.header'));
}
function makeElementDraggable(element, handle) {
let isDragging = false;
let offsetX, offsetY;
handle.addEventListener('mousedown', function(e) {
isDragging = true;
offsetX = e.clientX - element.getBoundingClientRect().left;
offsetY = e.clientY - element.getBoundingClientRect().top;
});
document.addEventListener('mousemove', function(e) {
if (!isDragging) return;
const x = e.clientX - offsetX;
const y = e.clientY - offsetY;
const maxX = window.innerWidth - element.offsetWidth;
const maxY = window.innerHeight - element.offsetHeight;
element.style.left = Math.max(0, Math.min(x, maxX)) + 'px';
element.style.top = Math.max(0, Math.min(y, maxY)) + 'px';
element.style.bottom = 'auto';
});
document.addEventListener('mouseup', function() {
isDragging = false;
});
}
function initialize() {
blockAds();
blockPopups();
applyDarkMode();
applySpeedBoost();
createUI();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize);
} else {
initialize();
}
})();