Skip to content

Commit e22d34f

Browse files
committed
a
Signed-off-by: magicoflolis <magicoflolis@gmail.com>
1 parent 2b9ee10 commit e22d34f

31 files changed

Lines changed: 51043 additions & 0 deletions

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 10
3+
4+
}

extension/background.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>UserJS</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="./js/psl.min.js"></script>
9+
<script src="./js/background.js"></script>
10+
</body>
11+
</html>

extension/img/icon_128.png

9.93 KB
Loading

extension/img/icon_16.png

458 Bytes
Loading

extension/img/icon_32.png

852 Bytes
Loading

extension/img/icon_96.png

4.63 KB
Loading

extension/js/background.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const countApi = 'https://greasyfork.org/scripts/by-site.json',
2+
adultAPI = 'https://sleazyfork.org/scripts/by-site.json',
3+
sleazy = browser.runtime.getURL("js/sleazyfork.js"),
4+
greasy = document.location.host,
5+
s = document.createElement("script");
6+
s.type = "module";
7+
s.src = sleazy;
8+
s.crossOrigin = "anonymous";
9+
10+
function getCurrentTabUrl(callback) {
11+
// Query filter to be passed to chrome.tabs.query - see
12+
// https://developer.chrome.com/extensions/tabs#method-query
13+
let queryInfo = {
14+
active: true,
15+
currentWindow: true
16+
};
17+
18+
chrome.tabs.query(queryInfo, (tabs) => {
19+
let tab = tabs[0],
20+
url = tab.url;
21+
console.assert(typeof url == 'string', 'tab.url should be a string');
22+
23+
callback(url);
24+
});
25+
}
26+
27+
function getUrlHost(url) {
28+
let a = document.createElement('a');
29+
a.href = url;
30+
let mainHost = psl.get(a.hostname) || a.hostname.split('.').splice(-2).join('.')
31+
return mainHost;
32+
}
33+
34+
function changeBadge(data) {
35+
getCurrentTabUrl(function (url) {
36+
let host = getUrlHost(url),
37+
count = data[host];
38+
count = count > 50 ? 50 : count;
39+
sessionStorage.setItem('host', host);
40+
if (count) {
41+
chrome.browserAction.setBadgeText({
42+
text: count.toString()
43+
});
44+
} else {
45+
chrome.browserAction.setBadgeText({
46+
text: ''
47+
});
48+
}
49+
});
50+
}
51+
fetch(adultAPI).then((r) => {
52+
r.json().then((data) => {
53+
console.log('count data loaded!');
54+
chrome.tabs.onUpdated.addListener(() => {
55+
changeBadge(data);
56+
});
57+
chrome.tabs.onActivated.addListener(() => {
58+
changeBadge(data);
59+
});
60+
});
61+
});
62+
fetch(countApi).then((r) => {
63+
r.json().then((data) => {
64+
console.log('count data loaded!');
65+
chrome.tabs.onUpdated.addListener(() => {
66+
changeBadge(data);
67+
});
68+
chrome.tabs.onActivated.addListener(() => {
69+
changeBadge(data);
70+
});
71+
});
72+
});

0 commit comments

Comments
 (0)