עדכון גרסה 1.0.3
חדש:
נוספה בדיקה גם על אתרים שמוטמע בהם סרטוני יוטיוב
Spoiler
יש מגבלה טכנית באתרים בהם מוטמע הסרטון שבגלילה הנקודה הירוקה "רודפת" אחרי הסרטון, מי שזה מפריע לו יוכל להפסיק את הבדיקה בפאנל הניהול
וכן נוסף פאנל ניהול לתוסף
התקנה דרך https://extsync.com/ של @אברהם-גלסר כולל תמיכה בעדכונים אוטומטיים
קישור ישיר להתקנה - https://extsync.com/install/TeBFjXhtX11aVcX1Gg9EEvTdYnV9nJroxyg3n5LbXdU
משם ניתן להוריד גם את הזיפ
קוד לTampermonkey בספויילר
Spoiler
// ==UserScript==
// @name נקודה ירוקה לנטפרי - יוטיוב
// @namespace netfree-youtube-dot
// @version 1.1
// @description מציג נקודה ירוקה על כל סרטון בעמוד ערוץ יוטיוב שמאושר (מחזיר 200) בנטפרי
// @author you
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @connect www.youtube.com
// @run-at document-idle
// ==/UserScript==
(function () {
"use strict";
const DEBUG = true;
const CONCURRENCY = 5;
const cache = new Map(); // videoId -> true/false/'pending'
const queue = [];
let running = 0;
const processedVideoIds = new Set();
const stats = { rawLinks: 0, found: 0, checking: 0, approved: 0, blocked: 0 };
function log(...args) {
if (DEBUG) console.log("[NF]", ...args);
}
// --- הגדרות (נשמרות דרך Tampermonkey, נגישות מתפריט התוסף) ---
const settings = {
enableOtherSites: GM_getValue("enableOtherSites", true),
showDebugPanel: GM_getValue("showDebugPanel", true),
};
GM_registerMenuCommand(
(settings.enableOtherSites ? "✅" : "⬜") + " הצג גם באתרים חוץ מיוטיוב (לחץ לשינוי, ידרוש רענון)",
() => {
GM_setValue("enableOtherSites", !settings.enableOtherSites);
location.reload();
}
);
GM_registerMenuCommand(
(settings.showDebugPanel ? "✅" : "⬜") + " הצג פאנל מידע צף (לחץ לשינוי, ידרוש רענון)",
() => {
GM_setValue("showDebugPanel", !settings.showDebugPanel);
location.reload();
}
);
// --- פאנל דיבוג צף על הדף ---
let panelEl = null;
function createPanel() {
panelEl = document.createElement("div");
panelEl.id = "nf-debug-panel";
panelEl.style.cssText = [
"position:fixed",
"bottom:16px",
"left:16px",
"z-index:2147483647",
"background:#111",
"color:#fff",
"font-family:sans-serif",
"font-size:12px",
"line-height:1.6",
"padding:10px 14px",
"border-radius:8px",
"box-shadow:0 2px 8px rgba(0,0,0,0.4)",
"direction:rtl",
"min-width:210px",
"opacity:0.92",
].join(";");
panelEl.innerHTML = `
<div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
<div style="font-weight:bold;">🟢 נטפרי-דוט פעיל (Tampermonkey)</div>
<button id="nf-panel-close" style="background:none; border:none; color:#fff; font-size:14px; cursor:pointer; line-height:1; padding:0 2px;">✕</button>
</div>
<div id="nf-panel-body">התחלת סריקה...</div>
`;
document.body.appendChild(panelEl);
panelEl.querySelector("#nf-panel-close").addEventListener("click", () => {
panelEl.remove();
panelEl = null;
});
log("פאנל דיבוג נוצר על הדף");
}
function updatePanel() {
if (!panelEl) return;
const body = panelEl.querySelector("#nf-panel-body");
if (body) {
body.innerHTML = `
קישורים גולמיים: ${stats.rawLinks}<br/>
סרטונים ייחודיים: ${stats.found}<br/>
בבדיקה: ${stats.checking}<br/>
מאושרים (200): ${stats.approved}<br/>
חסומים/שגיאה: ${stats.blocked}
`;
}
}
function ensurePanel() {
if (panelEl || !settings.showDebugPanel) return;
createPanel();
updatePanel();
}
// --- חיפוש עמוק שחודר גם ל-Shadow DOM ---
function deepQueryAll(selector, root) {
const results = [];
const walk = (node) => {
if (node.querySelectorAll) {
node.querySelectorAll(selector).forEach((el) => results.push(el));
node.querySelectorAll("*").forEach((el) => {
if (el.shadowRoot) walk(el.shadowRoot);
});
}
};
walk(root || document);
return results;
}
function getVideoId(href) {
try {
const url = new URL(href, location.href);
if (url.pathname === "/watch") return url.searchParams.get("v");
const shortsMatch = url.pathname.match(/\/shorts\/([^/?]+)/);
if (shortsMatch) return shortsMatch[1];
} catch (e) {
/* ignore */
}
return null;
}
function addBadge(container) {
if (!container || container.querySelector(".nf-green-dot")) return;
const style = getComputedStyle(container);
if (style.position === "static") {
container.style.position = "relative";
}
const dot = document.createElement("div");
dot.className = "nf-green-dot";
dot.title = "מאושר בנטפרי";
// סגנון inline מפורש - כי אלמנטים בתוך Shadow DOM לא בהכרח
// נחשפים לגיליון סגנונות חיצוני
dot.style.cssText = [
"position:absolute",
"top:6px",
"left:6px",
"width:14px",
"height:14px",
"background-color:#22c55e",
"border:2px solid #ffffff",
"border-radius:50%",
"box-shadow:0 0 3px rgba(0,0,0,0.6)",
"z-index:999",
"pointer-events:none",
"display:block",
].join(";");
container.appendChild(dot);
}
// --- באדג' צף (position:fixed) מעל iframe מוטמע - כי אי אפשר להיכנס
// לתוך ה-DOM של ה-iframe עצמו (מקור אחר) ---
const iframeBadges = new Map(); // iframe element -> dot element
function ensureIframeBadge(iframe) {
if (iframeBadges.has(iframe)) return;
const dot = document.createElement("div");
dot.className = "nf-green-dot nf-iframe-dot";
dot.title = "מאושר בנטפרי";
dot.style.cssText = [
"position:fixed",
"width:14px",
"height:14px",
"background-color:#22c55e",
"border:2px solid #ffffff",
"border-radius:50%",
"box-shadow:0 0 3px rgba(0,0,0,0.6)",
"z-index:2147483647",
"pointer-events:none",
"display:none",
].join(";");
document.body.appendChild(dot);
iframeBadges.set(iframe, dot);
ensureRafLoop();
}
function repositionIframeBadges() {
iframeBadges.forEach((dot, iframe) => {
if (!iframe.isConnected) {
dot.remove();
iframeBadges.delete(iframe);
return;
}
const rect = iframe.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) {
dot.style.display = "none";
return;
}
dot.style.display = "block";
dot.style.top = rect.top + 6 + "px";
dot.style.left = rect.left + 6 + "px";
});
}
// לולאת requestAnimationFrame שרצה רק כל עוד יש לפחות נקודה אחת
// מעל iframe - תואמת לקצב הריענון של המסך, בלי לרוץ סתם על אתרים
// שאין בהם וידאו מוטמע.
let rafRunning = false;
function rafLoop() {
repositionIframeBadges();
if (iframeBadges.size > 0) {
requestAnimationFrame(rafLoop);
} else {
rafRunning = false;
}
}
function ensureRafLoop() {
if (!rafRunning) {
rafRunning = true;
requestAnimationFrame(rafLoop);
}
}
// --- בדיקת הרשת עצמה, דרך GM_xmlhttpRequest (מחוץ להקשר/CSP של הדף) ---
function checkVideo(videoId) {
return new Promise((resolve) => {
const url = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`;
GM_xmlhttpRequest({
method: "GET",
url,
onload: (res) => {
log(videoId, "->", res.status);
resolve(res.status === 200);
},
onerror: (err) => {
log(videoId, "-> ERROR", err);
resolve(false);
},
ontimeout: () => {
log(videoId, "-> TIMEOUT");
resolve(false);
},
});
});
}
function processQueue() {
while (running < CONCURRENCY && queue.length) {
const task = queue.shift();
running++;
task().finally(() => {
running--;
processQueue();
});
}
}
function enqueueCheck(videoId, applyBadge) {
if (cache.has(videoId)) {
const result = cache.get(videoId);
if (result === true) applyBadge();
return;
}
cache.set(videoId, "pending");
stats.checking++;
updatePanel();
queue.push(async () => {
const ok = await checkVideo(videoId);
cache.set(videoId, ok);
stats.checking--;
if (ok) {
stats.approved++;
applyBadge();
} else {
stats.blocked++;
}
updatePanel();
});
processQueue();
}
// דירוג "כמה טוב" קישור בתור מקום להצמדת הנקודה - עדיפות לתמונה ממוזערת
function scoreLink(link) {
let score = 0;
if (link.id === "thumbnail") score += 10;
if (link.querySelector("img, yt-image")) score += 5;
if (link.closest("ytd-thumbnail")) score += 5;
return score;
}
const isYouTubeSite =
location.hostname === "www.youtube.com" || location.hostname === "youtube.com";
function scan() {
if (isYouTubeSite) {
const links = deepQueryAll('a[href*="/watch?v="], a[href*="/shorts/"]');
stats.rawLinks = links.length;
const byVideo = new Map();
links.forEach((link) => {
const videoId = getVideoId(link.href);
if (!videoId) return;
const existing = byVideo.get(videoId);
if (!existing || scoreLink(link) > scoreLink(existing)) {
byVideo.set(videoId, link);
}
});
byVideo.forEach((link, videoId) => {
if (!processedVideoIds.has(videoId)) {
processedVideoIds.add(videoId);
stats.found++;
}
// תמיד קוראים ל-enqueueCheck: אם כבר אושר בעבר, זה רק יצמיד
// מחדש את הנקודה ללינק הנוכחי (למקרה שיוטיוב בנתה מחדש את ה-DOM)
enqueueCheck(videoId, () => addBadge(link));
});
}
if (isYouTubeSite || settings.enableOtherSites) {
scanIframes();
}
updatePanel();
}
// --- זיהוי סרטוני יוטיוב מוטמעים (iframe) בכל אתר אחר ---
function getEmbedVideoId(src) {
try {
const url = new URL(src, location.href);
const host = url.hostname.replace(/^www\./, "");
if (host !== "youtube.com" && host !== "youtube-nocookie.com") return null;
const m = url.pathname.match(/\/embed\/([^/?]+)/);
if (m) return m[1];
if (url.pathname === "/watch") return url.searchParams.get("v");
} catch (e) {
/* ignore */
}
return null;
}
function scanIframes() {
const iframes = document.querySelectorAll("iframe[src]");
iframes.forEach((iframe) => {
if (iframe.dataset.nfIframeChecked) return;
const videoId = getEmbedVideoId(iframe.src);
if (!videoId) return;
iframe.dataset.nfIframeChecked = "1";
if (!processedVideoIds.has(videoId)) {
processedVideoIds.add(videoId);
stats.found++;
}
ensurePanel();
ensureIframeBadge(iframe);
enqueueCheck(videoId, () => {
iframeBadges.get(iframe) && (iframeBadges.get(iframe).style.display = "block");
repositionIframeBadges();
});
});
}
let scanTimeout = null;
function scheduleScan() {
if (scanTimeout) return;
scanTimeout = setTimeout(() => {
scanTimeout = null;
scan();
}, 400);
}
const observer = new MutationObserver(() => scheduleScan());
function init() {
if (!document.body) {
setTimeout(init, 100);
return;
}
// אם הכיבוי חל על אתרים חיצוניים ואנחנו לא ביוטיוב - לא עושים כלום בכלל
if (!isYouTubeSite && !settings.enableOtherSites) {
log("מושבת באתר הזה לפי ההגדרות (הצג רק ביוטיוב)");
return;
}
if (isYouTubeSite && settings.showDebugPanel) {
createPanel();
updatePanel();
}
scan();
observer.observe(document.documentElement, { childList: true, subtree: true });
// רשת ביטחון: MutationObserver לא תופס שינויים בתוך Shadow DOM קיים,
// וגם iframes חדשים (למשל וידאו שנטען בגלילה) עשויים להתווסף בכל רגע
setInterval(scan, 2000);
}
log("סקריפט Tampermonkey נטען, מתחיל");
init();
document.addEventListener("yt-navigate-finish", () => {
log("ניווט חדש ביוטיוב, סורק שוב");
scheduleScan();
});
})();