Skip to content

Commit d87cb77

Browse files
authored
Merge pull request #228 from ajayyy/experimental-ajay
Invidious support fixes
2 parents 502bec5 + 36c4ebd commit d87cb77

10 files changed

+89
-38
lines changed

SB.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ SB.defaults = {
160160
"hideDeleteButtonPlayerControls": false,
161161
"hideDiscordLaunches": 0,
162162
"hideDiscordLink": false,
163-
"invidiousInstances": ["invidio.us", "invidiou.sh"]
163+
"invidiousInstances": ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
164+
"invidiousUpdateInfoShowCount": 0,
165+
"autoUpvote": true
164166
}
165167

166168
// Reset config

_locales/en/messages.json

+12
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,17 @@
374374
},
375375
"currentInstances": {
376376
"message": "Current Instances:"
377+
},
378+
"enableAutoUpvote": {
379+
"message": "Auto Upvote"
380+
},
381+
"whatAutoUpvote": {
382+
"message": "With this enabled, the extension will upvote all submissions you view if you do not report them. If the notice is disabled, this will not occur."
383+
},
384+
"invidiousInfo1": {
385+
"message": "Invidious (the 3rd party YouTube site) support has been added!"
386+
},
387+
"invidiousInfo2": {
388+
"message": "You MUST enable it in the options for it to work."
377389
}
378390
}

background.js

+34-29
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ chrome.tabs.onUpdated.addListener(function(tabId) {
1616
}, () => void chrome.runtime.lastError ); // Suppress error on Firefox
1717
});
1818

19-
chrome.runtime.onMessage.addListener(async function (request, sender, callback) {
20-
await wait(() => SB.config !== undefined);
21-
19+
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
2220
switch(request.message) {
2321
case "submitTimes":
2422
submitTimes(request.videoID, callback);
@@ -65,6 +63,8 @@ chrome.runtime.onMessage.addListener(async function (request, sender, callback)
6563

6664
//add help page on install
6765
chrome.runtime.onInstalled.addListener(function (object) {
66+
// This let's the config sync to run fully before checking.
67+
// This is required on Firefox
6868
setTimeout(function() {
6969
const userID = SB.config.userID;
7070

@@ -76,7 +76,11 @@ chrome.runtime.onInstalled.addListener(function (object) {
7676
//generate a userID
7777
const newUserID = generateUserID();
7878
//save this UUID
79-
SB.config.userID = newUserID;
79+
SB.config.userID = newUserID;
80+
81+
//TODO: Remove when invidious support is old
82+
// Don't show this to new users
83+
SB.config.invidiousUpdateInfoShowCount = 6;
8084
}
8185
}, 1500);
8286
});
@@ -132,34 +136,35 @@ function addSponsorTime(time, videoID, callback) {
132136
}
133137

134138
function submitVote(type, UUID, callback) {
135-
let userID = SB.config.userID;
139+
let userID = SB.config.userID;
136140

137-
if (userID == undefined || userID === "undefined") {
138-
//generate one
139-
userID = generateUserID();
140-
SB.config.userID = userID;
141+
if (userID == undefined || userID === "undefined") {
142+
//generate one
143+
userID = generateUserID();
144+
SB.config.userID = userID;
145+
}
146+
147+
//publish this vote
148+
sendRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
149+
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
150+
callback({
151+
successType: 1
152+
});
153+
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
154+
//duplicate vote
155+
callback({
156+
successType: 0,
157+
statusCode: xmlhttp.status
158+
});
159+
} else if (error) {
160+
//error while connect
161+
callback({
162+
successType: -1,
163+
statusCode: xmlhttp.status
164+
});
141165
}
142166

143-
//publish this vote
144-
sendRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
145-
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
146-
callback({
147-
successType: 1
148-
});
149-
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
150-
//duplicate vote
151-
callback({
152-
successType: 0,
153-
statusCode: xmlhttp.status
154-
});
155-
} else if (error) {
156-
//error while connect
157-
callback({
158-
successType: -1,
159-
statusCode: xmlhttp.status
160-
});
161-
}
162-
})
167+
});
163168
}
164169

165170
async function submitTimes(videoID, callback) {

content.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272

7373
.sponsorSkipNotice {
74-
min-width: 300px;
74+
min-width: 350px;
7575
background-color: rgba(28, 28, 28, 0.9);
7676
position: absolute;
7777
right: 5px;

content.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,16 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
556556
//send out the message saying that a sponsor message was skipped
557557
if (!SB.config.dontShowNotice) {
558558
let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip);
559+
560+
//TODO: Remove this when Invidious support is old
561+
if (SB.config.invidiousUpdateInfoShowCount < 5) {
562+
skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("invidiousInfo1"), chrome.i18n.getMessage("invidiousInfo2"));
563+
564+
SB.config.invidiousUpdateInfoShowCount += 1;
565+
}
566+
559567
//auto-upvote this sponsor
560-
if (SB.config.trackViewCount && !SB.config.disableAutoSkip) {
568+
if (SB.config.trackViewCount && !SB.config.disableAutoSkip && SB.config.autoUpvote) {
561569
vote(1, currentUUID, null);
562570
}
563571
}

help/index_en.html

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
Come contribute, make some suggestions and help out in the Discord: <a href="https://discord.gg/QnmVMpU">https://discord.gg/QnmVMpU</a>
2828
</p>
2929

30+
<a class="bigText" href="/options/options.html">Enable Invidious Support</a>
31+
32+
<p>
33+
Invidious is a third-party YouTube viewer. SponsorBlock now supports invidious along with YouTube. Please visit the options page to make sure everything is how you want it to be.
34+
</p>
35+
3036
<h1>How skipping works</h1>
3137

3238
<p class="projectPreview">

help/styles.css

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
:not(.hljs-keyword):not(.hljs-comment):not(.hljs-number):not(.hljs-string):not(pre):not(code) {
1+
.bigText {
2+
font-size: 50px;
3+
}
4+
5+
body {
26
background-color: #333333;
37
}
48

@@ -122,7 +126,7 @@ a {
122126
text-decoration: none;
123127
}
124128

125-
p,li {
129+
p,li,a {
126130
font-family: sans-serif;
127131
font-size: 20;
128132
color: #c4c4c4;

options/options.html

+17
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ <h1>__MSG_Options__</h1>
181181

182182
<div class="small-description">__MSG_whatDeleteButton__</div>
183183
</div>
184+
185+
<br/>
186+
<br/>
187+
188+
<div option-type="toggle" sync-option="autoUpvote">
189+
<label class="switch-container" label-name="__MSG_enableAutoUpvote__">
190+
<label class="switch">
191+
<input type="checkbox" checked>
192+
<span class="slider round"></span>
193+
</label>
194+
</label>
195+
196+
<br/>
197+
<br/>
198+
199+
<div class="small-description">__MSG_whatAutoUpvote__</div>
200+
</div>
184201

185202
<br/>
186203
<br/>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1",
12-
"dev": "web-ext run",
12+
"dev": "web-ext run --start-url https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm",
1313
"build": "web-ext build --overwrite-dest -i \"*(package-lock.json|README.md|package.json|config.js.example|firefox_manifest-extra.json|manifest.json.original|ignored|crowdin.yml)\""
1414
},
1515
"repository": {

popup.js

-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ async function runThePopup() {
231231
}
232232

233233
//load video times for this video
234-
setTimeout(()=> console.log( SB.config.sponsorTimes.set), 200 )
235234
let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID);
236235
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
237236
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
@@ -919,10 +918,8 @@ async function runThePopup() {
919918
type: type,
920919
UUID: UUID
921920
}, function(response) {
922-
console.log(response)
923921
if (response != undefined) {
924922
//see if it was a success or failure
925-
console.log(response)
926923
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
927924
//success (treat rate limits as a success)
928925
addVoteMessage(chrome.i18n.getMessage("voted"), UUID)

0 commit comments

Comments
 (0)