Skip to content

Commit

Permalink
Update Nov 16th
Browse files Browse the repository at this point in the history
odensc committed Nov 17, 2020
1 parent 2fe0c10 commit fc40608
Showing 5 changed files with 59 additions and 12 deletions.
35 changes: 24 additions & 11 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
chrome.webRequest.onBeforeSendHeaders.addListener(
({ requestHeaders }) => {
for (const header of requestHeaders) {
if (header.name.toLowerCase() === "user-agent")
header.value = "Googlebot";
}

return { requestHeaders };
},
{ urls: ["*://*.ttvnw.net/*"] },
["blocking", "requestHeaders"]
let userAgent = "";

chrome.storage.onChanged.addListener((changes) => {
if (changes.userAgent) userAgent = changes.userAgent.newValue;
});

chrome.storage.local.get(
{ userAgent: "Mediapartners-Google" },
({ userAgent: storageUserAgent }) => {
userAgent = storageUserAgent;

chrome.webRequest.onBeforeSendHeaders.addListener(
({ requestHeaders }) => {
for (const header of requestHeaders) {
if (header.name.toLowerCase() === "user-agent")
header.value = userAgent;
}

return { requestHeaders };
},
{ urls: ["*://*.ttvnw.net/*"] },
["blocking", "requestHeaders"]
);
}
);
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "TTV ad-block",
"version": "1.0.0",
"version": "1.1.0",
"description": "Block ads on that certain streaming website",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": true
},
"options_page": "options.html",
"permissions": [
"*://*.twitch.tv/*",
"*://*.ttvnw.net/*",
"storage",
"webRequest",
"webRequestBlocking"
]
21 changes: 21 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>TTV Ad-block Options</title>
</head>
<body>
<p>
Find the latest user agent on
<a
href="https://raw.githubusercontent.com/odensc/ttv-ublock/extension/user-agent.txt"
>
GitHub
</a>
</p>

<input class="userAgent" type="text" placeholder="User agent" />
<button class="save">Save</button>

<script src="options.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chrome.storage.local.get(
{ userAgent: "Mediapartners-Google" },
({ userAgent }) => (document.querySelector(".userAgent").value = userAgent)
);

document.querySelector(".save").addEventListener("click", () => {
chrome.storage.local.set({
userAgent: document.querySelector(".userAgent").value,
});
});
1 change: 1 addition & 0 deletions user-agent.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mediapartners-Google

0 comments on commit fc40608

Please sign in to comment.