Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
https://github.com/NanoAdblocker/NanoFilters/issues/218
Browse files Browse the repository at this point in the history
Also remove old & broken webnovel.com and fox.com rules
  • Loading branch information
jspenguin2017 committed Nov 8, 2018
1 parent 862e7f6 commit 4d309d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 131 deletions.
128 changes: 7 additions & 121 deletions src/content/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ if (a.debugMode) {
/*************************************************************************/

// Partially working

if (a.domCmp(["hulu.com"])) {
const performClick = (btn) => {
if (btn.classList.contains("nano-defender-clicked")) {
Expand Down Expand Up @@ -86,128 +85,15 @@ if (a.debugMode) {

/*************************************************************************/

if (a.domCmp(["fox.com"])) {
// https://github.com/jspenguin2017/uBlockProtector/issues/660
a.replaceXHR(() => {

console.warn("[Nano] xhr", url);

if (url.includes("uplynk.com/preplay")) {
this.addEventListener("readystatechange", () => {
if (this.readyState === 4) {
try {

console.warn(this.responseText);

let payload = window.JSON.parse(this.responseText);
payload.ads = {};
replace(this, window.JSON.stringify(payload));
} catch (err) { }
}
});
// https://github.com/NanoAdblocker/NanoFilters/issues/218
if (a.domCmp(["di.fm", "jazzradio.com"])) {
a.loopbackXHR((ignored, url) => {
if (url.startsWith("https://pubads.g.doubleclick.net/")) {
return `<?xml version="1.0" encoding="UTF-8"?>
<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="3.0">
</VAST>`;
}
});
a.inject(() => {
"use strict";
const _fetch = window.fetch;
window.fetch = (...args) => {

console.warn("[Nano] fetch", args);

return _fetch.apply(window, args);
};
});
}

/*************************************************************************/

if (a.domCmp(["webnovel.com"])) {
// https://github.com/jspenguin2017/uBlockProtector/issues/457
const bookExtractor = /\/book\/([^/]+)/;
let isInBackground = false;
const scanner = () => {
if (isInBackground) {
return;
}
$(".cha-content._lock").each((lock) => {
lock.classList.remove("_lock");
const video = lock.closest(".chapter_content").querySelector(".lock-video");
if (video) {
video.remove();
}

const contentElem = lock.querySelector(".cha-words");
contentElem.insertAdjacentHTML("beforeend", "<p style='opacity:0.5;'>" +
"Nano Defender is fetching the rest of this chapter, this can take up to 15 seconds.</p>");

const bookID = bookExtractor.exec(location.href)[1];
const chapterID = lock.querySelector("[data-cid]").dataset.cid;
if (!bookID || !chapterID) {
return;
}
const cookie = encodeURIComponent(a.cookie("_csrfToken"));

$.request({
method: "GET",
url: `https://www.webnovel.com/apiajax/chapter/GetChapterContentToken?_csrfToken=` +
`${cookie}&bookId=${bookID}&chapterId=${chapterID}`,
}, (data) => {
try {
let token = JSON.parse(data).data.token;
token = encodeURIComponent(token);
fetchChapter(cookie, token, contentElem);
} catch (err) {
console.error("[Nano] Failed :: Find Chapter Token");
}
}, () => {
console.error("[Nano] Failed :: Find Chapter Token");
});
});
};
const fetchChapter = (cookie, token, contentElem) => {
const tick = () => {
$.request({
method: "GET",
url: `https://www.webnovel.com/apiajax/chapter/GetChapterContentByToken?_csrfToken=` +
`${cookie}&token=${token}`,
}, (data) => {
try {
const content = JSON.parse(data).data.content.trim();
if (content) {
contentElem.innerHTML = content;
setTimeout(() => {
drawChapter(content, contentElem);
}, 500);
} else {
setTimeout(tick, 2000);
}
} catch (err) {
setTimeout(tick, 2000);
}
}, () => {
setTimeout(tick, 2000);
});
};
tick();
};
const drawChapter = (content, contentElem) => {
if (!contentElem.innerHTML.includes("<p>")) {
const lines = content.split("\n");
contentElem.innerHTML = "";
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (!line) {
continue;
}
const p = document.createElement("p");
p.textContent = line;
contentElem.append(p);
}
}
};
setInterval(scanner, 1000);
a.on("focus", () => { isInBackground = false; });
a.on("blur", () => { isInBackground = true; });
}

/*************************************************************************/
Expand Down
9 changes: 0 additions & 9 deletions src/content/rules-specific.js
Original file line number Diff line number Diff line change
Expand Up @@ -2121,15 +2121,6 @@ if (a.domCmp(["itv.com"])) {
}
});
}
if (a.domCmp(["di.fm", "jazzradio.com"])) {
a.loopbackXHR((ignored, url) => {
if (url.startsWith("https://pubads.g.doubleclick.net/")) {
return `<?xml version="1.0" encoding="UTF-8"?>
<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="3.0">
</VAST>`;
}
});
}
if (a.domCmp(["stream.nbcsports.com"])) {
a.loopbackXHR((ignored, url) => {
if (url.includes(".v.fwmrm.net/ad/g/1")) {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"webRequest",
"webRequestBlocking"
],
"version": "15.0.0.70",
"version": "15.0.0.71",
"web_accessible_resources": [
"resources/*"
]
Expand Down

0 comments on commit 4d309d4

Please sign in to comment.