Adblock panel draggable, slide-down toggle, GM storage, ad-* patterns, header protection, SPA safe, multi-network toggle
目前為
// ==UserScript==
// @name Advanced AdBlocker Panel v6.11
// @namespace baba-scripts
// @version 6.11
// @description Adblock panel draggable, slide-down toggle, GM storage, ad-* patterns, header protection, SPA safe, multi-network toggle
// @author Volkan
// @match *://*/*
// @grant GM_setValue
// @grant GM_getValue
// @license MIT
// ==/UserScript==
(function() {
'use strict';
if (window.top !== window.self) return; // iframe içine panel eklenmez
// --- CSS ---
const style = document.createElement("style");
style.textContent = `
#adblock-panel {
position: fixed; top: 10px; right: 10px; width: 250px;
background: #1a1a1a; color: white; font-family: Arial, sans-serif;
border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.5);
overflow: hidden; z-index: 999999; cursor: default;
}
#adblock-header { padding:10px; cursor: move; background:#2a2a2a;
display:flex; align-items:center; gap:8px; font-weight:bold; user-select:none; }
#adblock-header::before { content:"🛡️"; }
#adblock-body { max-height:0; overflow:hidden; transition:max-height 0.4s ease, opacity 0.4s ease; opacity:0; }
#adblock-body.open { max-height:600px; opacity:1; }
.adblock-item { padding:8px 12px; border-top:1px solid #333; font-size:14px; }
.adblock-warning { color:#ffcc00; }
.adblock-pause { color:#00ccff; cursor:pointer; }
.adblock-network { display:flex; justify-content:space-between; align-items:center; margin-top:4px; }
.adblock-network input { cursor:pointer; }
`;
document.head.appendChild(style);
// --- Panel ---
const panel = document.createElement("div"); panel.id="adblock-panel";
const header = document.createElement("div"); header.id="adblock-header"; header.textContent="AdBlock Panel";
const body = document.createElement("div"); body.id="adblock-body";
// Ad counter
let adCounterSpan = document.createElement("span"); adCounterSpan.id="ad-count";
const adCounter = document.createElement("div"); adCounter.className="adblock-item";
adCounter.appendChild(document.createTextNode("Ad Counter: "));
adCounter.appendChild(adCounterSpan);
// Warning
const warning = document.createElement("div"); warning.className="adblock-item adblock-warning";
warning.textContent = "⚠️ Ads Blocked";
// Pause
const pauseBtn = document.createElement("div"); pauseBtn.className="adblock-item adblock-pause"; pauseBtn.id="adblock-pause";
// Network toggle
const networksDiv = document.createElement("div"); networksDiv.className="adblock-item";
networksDiv.textContent="Networks:";
const networkList = [
{name:"Google Ads", key:"google"},
{name:"Yahoo Ads", key:"yahoo"},
{name:"MSN Ads", key:"msn"},
{name:"Turkish Reklam1", key:"tr1"},
{name:"Turkish Reklam2", key:"tr2"}
];
const networkToggles = {};
networkList.forEach(n=>{
const container = document.createElement("div"); container.className="adblock-network";
const label = document.createElement("label"); label.textContent=n.name;
const chk = document.createElement("input"); chk.type="checkbox";
chk.checked = GM_getValue(`network_${n.key}`, true);
chk.addEventListener("change", ()=>GM_setValue(`network_${n.key}`, chk.checked));
networkToggles[n.key]=chk;
container.appendChild(label); container.appendChild(chk); networksDiv.appendChild(container);
});
body.appendChild(adCounter); body.appendChild(warning); body.appendChild(pauseBtn); body.appendChild(networksDiv);
panel.appendChild(header); panel.appendChild(body); document.body.appendChild(panel);
// --- GM Storage ---
let isOpen = GM_getValue("panelOpen", false);
let adCount = GM_getValue("adCount",0)||0;
let pauseActive = GM_getValue("pauseActive", false);
if(isOpen) body.classList.add("open");
adCounterSpan.textContent = adCount;
pauseBtn.textContent = pauseActive ? "▶ Resume Blocking" : "⏸ Pause Blocking";
// --- Toggle panel ---
header.addEventListener("click", e=>{
if(e.target !== header) return;
isOpen = !isOpen; GM_setValue("panelOpen", isOpen);
body.classList.toggle("open", isOpen);
});
// --- Pause toggle ---
pauseBtn.addEventListener("click",e=>{
e.stopPropagation();
pauseActive=!pauseActive; GM_setValue("pauseActive",pauseActive);
pauseBtn.textContent=pauseActive ? "▶ Resume Blocking" : "⏸ Pause Blocking";
});
// --- Drag ---
let offsetX=0, offsetY=0, isDragging=false;
header.addEventListener("mousedown",e=>{isDragging=true; offsetX=e.clientX-panel.getBoundingClientRect().left; offsetY=e.clientY-panel.getBoundingClientRect().top; e.preventDefault();});
document.addEventListener("mousemove",e=>{if(!isDragging) return; panel.style.left=(e.clientX-offsetX)+"px"; panel.style.top=(e.clientY-offsetY)+"px"; panel.style.right="auto";});
document.addEventListener("mouseup",e=>{isDragging=false;});
// --- Ad block ---
const adPatterns = [/^ad-/ , /^-ad/, /^ad_/, /_ad$/];
const blockedTagNames = ['div','section','ins','iframe','span'];
const protectedHeaderClasses = ['header','nav','masthead','topbar','ytp-chrome-top','site-header'];
function isProtected(el){ if(!el) return false; const classId=(el.className+" "+el.id).toLowerCase(); return protectedHeaderClasses.some(p=>classId.includes(p)); }
function matchesAdPattern(str){ if(!str) return false; str=str.toLowerCase(); if(str==="ad") return true; return adPatterns.some(r=>r.test(str)); }
function blockAds(node=document){
if(pauseActive) return;
blockedTagNames.forEach(tag=>{
node.querySelectorAll(tag).forEach(el=>{
if(!el || isProtected(el)) return;
const names=[el.className,el.id].filter(Boolean);
if(names.some(matchesAdPattern)){
el.remove(); adCount++;
GM_setValue("adCount",adCount);
// Ad counter span check
if(!adCounterSpan.isConnected){
const newSpan=document.getElementById("ad-count");
if(newSpan) adCounterSpan=newSpan;
}
adCounterSpan.textContent=adCount;
}
});
});
}
// --- Observer ---
const observer = new MutationObserver(muts=>{ muts.forEach(m=>{ m.addedNodes.forEach(n=>{ if(n.nodeType===1) blockAds(n); }); }); });
observer.observe(document.body,{childList:true,subtree:true});
// --- Interval backup ---
setInterval(()=>blockAds(document.body),3000);
})();