@whoisjayd/tizenliv 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +88 -0
- package/dist/userScript.js +312 -0
- package/launcher.html +82 -0
- package/package.json +36 -0
- package/src/adblocker.js +20 -0
- package/src/consent.js +15 -0
- package/src/dom.js +45 -0
- package/src/network.js +83 -0
- package/src/rules.js +62 -0
- package/src/scripts.js +61 -0
- package/src/userScript.js +3 -0
package/src/rules.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const SONYLIV_CSS_SELECTORS = [
|
|
2
|
+
'[class*="adblock"]',
|
|
3
|
+
'[id*="adblock"]',
|
|
4
|
+
'[class*="AdBlock"]',
|
|
5
|
+
'[id*="AdBlock"]',
|
|
6
|
+
'[class*="ad-banner"]',
|
|
7
|
+
'[id*="ad-banner"]',
|
|
8
|
+
'[class*="AdBanner"]',
|
|
9
|
+
'[id*="AdBanner"]',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const BLOCK_RULES = [
|
|
13
|
+
{
|
|
14
|
+
reason: 'SonyLIV beacon endpoint',
|
|
15
|
+
matches: function matches(url) {
|
|
16
|
+
return url.hostname === 'api-godavari.sonyliv.com' && /\/beacon(?:\?|\/|$)/i.test(url.pathname + url.search);
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const CONSENT_STORAGE_ENTRIES = [
|
|
22
|
+
['cookie_acceptance', 'true'],
|
|
23
|
+
['essential_cookies_acceptance', 'true'],
|
|
24
|
+
['session_cookies_acceptance', 'true'],
|
|
25
|
+
['analytics_cookies_acceptance', 'false'],
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export function getBlockedReason(input) {
|
|
29
|
+
const url = toUrl(input);
|
|
30
|
+
if (!url) return null;
|
|
31
|
+
|
|
32
|
+
for (const rule of BLOCK_RULES) {
|
|
33
|
+
if (rule.matches(url)) return rule.reason;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function shouldStripScriptSource(input) {
|
|
40
|
+
const url = toUrl(input);
|
|
41
|
+
if (!url) return false;
|
|
42
|
+
|
|
43
|
+
return url.hostname === 'imasdk.googleapis.com' && url.pathname === '/js/sdkloader/ima3.js';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getConsentStorageEntries() {
|
|
47
|
+
return CONSENT_STORAGE_ENTRIES.map(function cloneEntry(entry) {
|
|
48
|
+
return [entry[0], entry[1]];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function toUrl(input) {
|
|
53
|
+
try {
|
|
54
|
+
const base = typeof window !== 'undefined' && window.location ? window.location.href : 'https://www.sonyliv.com/';
|
|
55
|
+
if (input && typeof input === 'object' && 'url' in input) {
|
|
56
|
+
return new URL(input.url, base);
|
|
57
|
+
}
|
|
58
|
+
return new URL(String(input), base);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/scripts.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function installScriptSourceStripper(shouldStripScriptSource, loggerName) {
|
|
2
|
+
if (typeof document === 'undefined' || !document.createElement || document.createElement.__tizenAdBlockPatched) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const originalCreateElement = document.createElement.bind(document);
|
|
7
|
+
|
|
8
|
+
document.createElement = function patchedCreateElement(tagName, options) {
|
|
9
|
+
const element = originalCreateElement(tagName, options);
|
|
10
|
+
|
|
11
|
+
if (String(tagName).toLowerCase() === 'script') {
|
|
12
|
+
patchScriptElement(element, shouldStripScriptSource, loggerName);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return element;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
document.createElement.__tizenAdBlockPatched = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function patchScriptElement(element, shouldStripScriptSource, loggerName) {
|
|
22
|
+
const descriptor = getScriptSrcDescriptor();
|
|
23
|
+
const originalSetAttribute = element.setAttribute;
|
|
24
|
+
|
|
25
|
+
if (descriptor && descriptor.configurable) {
|
|
26
|
+
Object.defineProperty(element, 'src', {
|
|
27
|
+
configurable: true,
|
|
28
|
+
enumerable: descriptor.enumerable,
|
|
29
|
+
get: function getSrc() {
|
|
30
|
+
return descriptor.get.call(this);
|
|
31
|
+
},
|
|
32
|
+
set: function setSrc(value) {
|
|
33
|
+
descriptor.set.call(this, getSafeScriptSource(value, shouldStripScriptSource, loggerName));
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
element.setAttribute = function patchedSetAttribute(name, value) {
|
|
39
|
+
if (String(name).toLowerCase() === 'src') {
|
|
40
|
+
return originalSetAttribute.call(this, name, getSafeScriptSource(value, shouldStripScriptSource, loggerName));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return originalSetAttribute.apply(this, arguments);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getScriptSrcDescriptor() {
|
|
48
|
+
if (typeof HTMLScriptElement === 'undefined') return null;
|
|
49
|
+
return Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getSafeScriptSource(value, shouldStripScriptSource, loggerName) {
|
|
53
|
+
const source = String(value || '');
|
|
54
|
+
if (!shouldStripScriptSource(source)) return value;
|
|
55
|
+
|
|
56
|
+
if (typeof console !== 'undefined' && console.debug) {
|
|
57
|
+
console.debug('[' + loggerName + '] stripped script source ' + source);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return 'data:text/javascript,/* stripped by ' + encodeURIComponent(loggerName) + ' */';
|
|
61
|
+
}
|