mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da20709512 | ||
|
|
6ff461fa86 | ||
|
|
e205447968 | ||
|
|
ff6234bffe | ||
|
|
d93d475c1f | ||
|
|
0d0b919106 | ||
|
|
366fd43752 | ||
|
|
1119adffb7 | ||
|
|
9d14f02bec | ||
|
|
9fada00028 | ||
|
|
e0d2436372 | ||
|
|
e4c94aa5c5 | ||
|
|
e3e4121a21 | ||
|
|
a75ea50098 | ||
|
|
6b6e74b5a0 | ||
|
|
d6c5dbaff1 | ||
|
|
a66804064a | ||
|
|
919f9f56bd | ||
|
|
bd614e250b | ||
|
|
6275c2d62c | ||
|
|
feea7aa51d | ||
|
|
16263d463f | ||
|
|
6673272e14 | ||
|
|
6358ba2e11 | ||
|
|
2415784eee | ||
|
|
acb3c67629 | ||
|
|
622b2ea158 | ||
|
|
7a9af6cbcf | ||
|
|
51a389284d | ||
|
|
2ff70f1511 | ||
|
|
ff9badf2e9 | ||
|
|
aefc880486 | ||
|
|
e749456719 | ||
|
|
a2312a10be | ||
|
|
b0090a3334 | ||
|
|
7100831956 | ||
|
|
30c1b2d919 | ||
|
|
3ec6caee9d | ||
|
|
7f505a52ca | ||
|
|
84b8e59b39 | ||
|
|
808dfe42ce | ||
|
|
600365d998 | ||
|
|
569699cbc1 | ||
|
|
08cb324125 | ||
|
|
504f0b0ede | ||
|
|
00877fb087 | ||
|
|
d654d8934b | ||
|
|
97e202dbd0 | ||
|
|
64be41b008 | ||
|
|
b3684a8730 | ||
|
|
45f0d65f69 | ||
|
|
5436a1651e | ||
|
|
33fe63084b | ||
|
|
8f47513c98 | ||
|
|
7a17cc2b0a | ||
|
|
c7cb845d8a | ||
|
|
250c75a78f | ||
|
|
a86e55ac67 | ||
|
|
30f2f638fe | ||
|
|
725ab783e3 | ||
|
|
30e3222177 | ||
|
|
d9789c20d6 | ||
|
|
c8114e2d7e | ||
|
|
c7da0f0c65 | ||
|
|
0f561d4a5a | ||
|
|
55c7529731 |
2
LICENSE
2
LICENSE
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
SponsorBlock Copyright (C) 2019 Ajay Ramachandran and other SponsorBlock contributors
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.
|
SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.
|
||||||
|
|
||||||
|
# Available for Chrome and Firefox
|
||||||
|
|
||||||
|
Chrome: https://chrome.google.com/webstore/detail/ajjollijmimolcncegpgkbilohbhjnhi
|
||||||
|
|
||||||
|
Firefox: https://addons.mozilla.org/addon/sponsorblock/
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
|
|
||||||
The backend server code is available here: https://github.com/ajayyy/SponsorBlockServer
|
The backend server code is available here: https://github.com/ajayyy/SponsorBlockServer
|
||||||
@@ -19,16 +25,14 @@ Hopefully this project can be combined with projects like [this](https://github.
|
|||||||
|
|
||||||
This project is partially based off of [this experimental extension](https://github.com/OfficialNoob/YTSponsorSkip). That extension has the basic video skipping functionality.
|
This project is partially based off of [this experimental extension](https://github.com/OfficialNoob/YTSponsorSkip). That extension has the basic video skipping functionality.
|
||||||
|
|
||||||
# Chrome extension
|
# Build Yourself
|
||||||
|
|
||||||
It will be on the chrome webstore soon once I get some more UI features in, such as an icon. For now, you can load this project as an unpacked extension. Make sure to rename the `config.js.example` file to `config.js` before installing.
|
You can load this project as an unpacked extension. Make sure to rename the `config.js.example` file to `config.js` before installing.
|
||||||
|
|
||||||
# Firefox extension
|
|
||||||
|
|
||||||
None at the moment
|
|
||||||
|
|
||||||
# Credit
|
# Credit
|
||||||
|
|
||||||
The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) is used to grab the time the video was published.
|
The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) is used to grab the time the video was published.
|
||||||
|
|
||||||
Some icons made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> and are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
Some icons made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> and are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
||||||
|
|
||||||
|
Some icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
||||||
|
|||||||
@@ -3,34 +3,40 @@ var previousVideoID = null
|
|||||||
//the id of this user, randomly generated once per install
|
//the id of this user, randomly generated once per install
|
||||||
var userID = null;
|
var userID = null;
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener( // On tab update
|
//when a new tab is highlighted
|
||||||
function(tabId, changeInfo, tab) {
|
chrome.tabs.onActivated.addListener(
|
||||||
if (changeInfo != undefined && changeInfo.url != undefined) {
|
function(activeInfo) {
|
||||||
let id = getYouTubeVideoID(changeInfo.url);
|
chrome.tabs.get(activeInfo.tabId, function(tab) {
|
||||||
if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id
|
let id = getYouTubeVideoID(tab.url);
|
||||||
videoIDChange(id);
|
|
||||||
|
|
||||||
chrome.tabs.sendMessage( tabId, {
|
//if this even is a YouTube tab
|
||||||
message: 'ytvideoid',
|
if (id) {
|
||||||
id: id
|
videoIDChange(id, activeInfo.tabId);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//when a tab changes URLs
|
||||||
|
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
||||||
|
if (changeInfo != undefined && changeInfo.url != undefined) {
|
||||||
|
let id = getYouTubeVideoID(changeInfo.url);
|
||||||
|
|
||||||
|
//if URL changed and is youtube video message contentScript the video id
|
||||||
|
if (changeInfo.url && id) {
|
||||||
|
videoIDChange(id, tabId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
if (request.message == "submitTimes") {
|
if (request.message == "submitTimes") {
|
||||||
submitTimes(request.videoID, callback);
|
submitTimes(request.videoID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later by the submitTimes function
|
//this allows the callback to be called later by the submitTimes function
|
||||||
return true;
|
return true;
|
||||||
} else if (request.message == "ytvideoid") {
|
|
||||||
if (previousVideoID != request.videoID) {
|
|
||||||
videoIDChange(request.videoID);
|
|
||||||
}
|
|
||||||
} else if (request.message == "addSponsorTime") {
|
} else if (request.message == "addSponsorTime") {
|
||||||
addSponsorTime(request.time);
|
addSponsorTime(request.time, request.videoID);
|
||||||
} else if (request.message == "getSponsorTimes") {
|
} else if (request.message == "getSponsorTimes") {
|
||||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||||
callback({
|
callback({
|
||||||
@@ -63,22 +69,22 @@ function getSponsorTimes(videoID, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSponsorTime(time) {
|
function addSponsorTime(time, videoID) {
|
||||||
getSponsorTimes(previousVideoID, function(sponsorTimes) {
|
getSponsorTimes(videoID, function(sponsorTimes) {
|
||||||
//add to sponsorTimes
|
//add to sponsorTimes
|
||||||
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
||||||
//it is an end time
|
//it is an end time
|
||||||
sponsorTimes[sponsorTimes.length - 1][1] = parseInt(time);
|
sponsorTimes[sponsorTimes.length - 1][1] = time;
|
||||||
} else {
|
} else {
|
||||||
//it is a start time
|
//it is a start time
|
||||||
let sponsorTimesIndex = sponsorTimes.length;
|
let sponsorTimesIndex = sponsorTimes.length;
|
||||||
sponsorTimes[sponsorTimesIndex] = [];
|
sponsorTimes[sponsorTimesIndex] = [];
|
||||||
|
|
||||||
sponsorTimes[sponsorTimesIndex][0] = parseInt(time);
|
sponsorTimes[sponsorTimesIndex][0] = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
//save this info
|
//save this info
|
||||||
let sponsorTimeKey = "sponsorTimes" + previousVideoID;
|
let sponsorTimeKey = "sponsorTimes" + videoID;
|
||||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -94,12 +100,14 @@ function submitVote(type, UUID, callback) {
|
|||||||
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
|
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
|
||||||
//duplicate vote
|
//duplicate vote
|
||||||
callback({
|
callback({
|
||||||
successType: 0
|
successType: 0,
|
||||||
|
statusCode: xmlhttp.status
|
||||||
});
|
});
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
//error while connect
|
//error while connect
|
||||||
callback({
|
callback({
|
||||||
successType: -1
|
successType: -1,
|
||||||
|
statusCode: xmlhttp.status
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -147,7 +155,13 @@ function submitTimes(videoID, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function videoIDChange(currentVideoID) {
|
function videoIDChange(currentVideoID, tabId) {
|
||||||
|
//send a message to the content script
|
||||||
|
chrome.tabs.sendMessage(tabId, {
|
||||||
|
message: 'ytvideoid',
|
||||||
|
id: currentVideoID
|
||||||
|
});
|
||||||
|
|
||||||
//warn them if they had unsubmitted times
|
//warn them if they had unsubmitted times
|
||||||
if (previousVideoID != null) {
|
if (previousVideoID != null) {
|
||||||
//get the sponsor times from storage
|
//get the sponsor times from storage
|
||||||
@@ -186,6 +200,12 @@ function getUserID(callback) {
|
|||||||
userID = userIDStorage;
|
userID = userIDStorage;
|
||||||
callback(userID);
|
callback(userID);
|
||||||
} else {
|
} else {
|
||||||
|
//double check if a UUID hasn't been created since this was first called
|
||||||
|
if (userID != null) {
|
||||||
|
callback(userID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//generate a userID
|
//generate a userID
|
||||||
userID = generateUUID();
|
userID = generateUUID();
|
||||||
|
|
||||||
|
|||||||
12
content.css
12
content.css
@@ -1,3 +1,15 @@
|
|||||||
|
.popup {
|
||||||
|
z-index: 10;
|
||||||
|
width: 100%;
|
||||||
|
height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smallLink {
|
||||||
|
font-size: 10px;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.playerButtonImage {
|
.playerButtonImage {
|
||||||
height: 60%;
|
height: 60%;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|||||||
457
content.js
457
content.js
@@ -1,28 +1,24 @@
|
|||||||
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
|
||||||
videoIDChange(id);
|
|
||||||
|
|
||||||
//tell background.js about this
|
|
||||||
chrome.runtime.sendMessage({
|
|
||||||
message: "ytvideoid",
|
|
||||||
videoID: id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//was sponsor data found when doing SponsorsLookup
|
//was sponsor data found when doing SponsorsLookup
|
||||||
var sponsorDataFound = false;
|
var sponsorDataFound = false;
|
||||||
|
|
||||||
//the actual sponsorTimes if loaded and UUIDs associated with them
|
//the actual sponsorTimes if loaded and UUIDs associated with them
|
||||||
var sponsorTimes = undefined;
|
var sponsorTimes = null;
|
||||||
var UUIDs = undefined;
|
var UUIDs = null;
|
||||||
|
//what video id are these sponsors for
|
||||||
|
var sponsorVideoID = null;
|
||||||
|
|
||||||
|
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
||||||
|
videoIDChange(id);
|
||||||
|
}
|
||||||
|
|
||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
//the last time looked at (used to see if this time is in the interval)
|
//the last time looked at (used to see if this time is in the interval)
|
||||||
var lastTime;
|
var lastTime = -1;
|
||||||
|
|
||||||
//the last time skipped to
|
//the actual time (not video time) that the last skip happened
|
||||||
var lastTimeSkippedTo = -1;
|
var lastUnixTimeSkipped = -1;
|
||||||
|
|
||||||
//the last time in the video a sponsor was skipped
|
//the last time in the video a sponsor was skipped
|
||||||
//used for the go back button
|
//used for the go back button
|
||||||
@@ -35,6 +31,23 @@ var showingStartSponsor = true;
|
|||||||
|
|
||||||
//should the video controls buttons be added
|
//should the video controls buttons be added
|
||||||
var hideVideoPlayerControls = false;
|
var hideVideoPlayerControls = false;
|
||||||
|
var hideInfoButtonPlayerControls = false;
|
||||||
|
var hideDeleteButtonPlayerControls = false;
|
||||||
|
|
||||||
|
//becomes true when isInfoFound is called
|
||||||
|
//this is used to close the popup on YouTube when the other popup opens
|
||||||
|
var popupInitialised = false;
|
||||||
|
|
||||||
|
//should view counts be tracked
|
||||||
|
var trackViewCount = false;
|
||||||
|
chrome.storage.sync.get(["trackViewCount"], function(result) {
|
||||||
|
let trackViewCountStorage = result.trackViewCount;
|
||||||
|
if (trackViewCountStorage != undefined) {
|
||||||
|
trackViewCount = trackViewCountStorage;
|
||||||
|
} else {
|
||||||
|
trackViewCount = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//if the notice should not be shown
|
//if the notice should not be shown
|
||||||
//happens when the user click's the "Don't show notice again" button
|
//happens when the user click's the "Don't show notice again" button
|
||||||
@@ -55,7 +68,7 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
|
|
||||||
//messages from popup script
|
//messages from popup script
|
||||||
if (request.message == "sponsorStart") {
|
if (request.message == "sponsorStart") {
|
||||||
sponsorMessageStarted();
|
sponsorMessageStarted(sendResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.message == "isInfoFound") {
|
if (request.message == "isInfoFound") {
|
||||||
@@ -64,7 +77,14 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
found: sponsorDataFound,
|
found: sponsorDataFound,
|
||||||
sponsorTimes: sponsorTimes,
|
sponsorTimes: sponsorTimes,
|
||||||
UUIDs: UUIDs
|
UUIDs: UUIDs
|
||||||
})
|
});
|
||||||
|
|
||||||
|
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
|
||||||
|
//the popup should be closed now that another is opening
|
||||||
|
closeInfoMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
popupInitialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.message == "getVideoID") {
|
if (request.message == "getVideoID") {
|
||||||
@@ -85,10 +105,55 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
hideVideoPlayerControls = request.value;
|
hideVideoPlayerControls = request.value;
|
||||||
|
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
} else if (request.message == "changeInfoButtonPlayerControlsVisibility") {
|
||||||
|
hideInfoButtonPlayerControls = request.value;
|
||||||
|
|
||||||
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
} else if (request.message == "changeDeleteButtonPlayerControlsVisibility") {
|
||||||
|
hideDeleteButtonPlayerControls = request.value;
|
||||||
|
|
||||||
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.message == "trackViewCount") {
|
||||||
|
trackViewCount = request.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//check for hotkey pressed
|
||||||
|
document.onkeydown = function(e){
|
||||||
|
e = e || window.event;
|
||||||
|
var key = e.which || e.keyCode;
|
||||||
|
|
||||||
|
let video = document.getElementById("movie_player");
|
||||||
|
|
||||||
|
//is the video in focus, otherwise they could be typing a comment
|
||||||
|
if (document.activeElement === video) {
|
||||||
|
if(key == 186){
|
||||||
|
//semicolon
|
||||||
|
startSponsorClicked();
|
||||||
|
} else if (key == 222) {
|
||||||
|
//single quote
|
||||||
|
submitSponsorTimes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function videoIDChange(id) {
|
function videoIDChange(id) {
|
||||||
|
//not a url change
|
||||||
|
if (sponsorVideoID == id){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset last sponsor times
|
||||||
|
lastTime = -1;
|
||||||
|
lastUnixTimeSkipped = -1;
|
||||||
|
|
||||||
|
//reset sponsor times
|
||||||
|
sponsorTimes = null;
|
||||||
|
UUIDs = null;
|
||||||
|
sponsorVideoID = id;
|
||||||
|
|
||||||
//reset sponsor data found check
|
//reset sponsor data found check
|
||||||
sponsorDataFound = false;
|
sponsorDataFound = false;
|
||||||
sponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
@@ -100,15 +165,17 @@ function videoIDChange(id) {
|
|||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
let sponsorTimes = response.sponsorTimes;
|
let sponsorTimes = response.sponsorTimes;
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
|
if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
|
||||||
document.getElementById("submitButton").style.display = "unset";
|
changeStartSponsorButton(true, true);
|
||||||
} else if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
} else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
||||||
toggleStartSponsorButton();
|
changeStartSponsorButton(false, true);
|
||||||
|
} else {
|
||||||
|
changeStartSponsorButton(true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//see if video control buttons should be added
|
//see if video controls buttons should be added
|
||||||
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
||||||
if (result.hideVideoPlayerControls != undefined) {
|
if (result.hideVideoPlayerControls != undefined) {
|
||||||
hideVideoPlayerControls = result.hideVideoPlayerControls;
|
hideVideoPlayerControls = result.hideVideoPlayerControls;
|
||||||
@@ -116,6 +183,21 @@ function videoIDChange(id) {
|
|||||||
|
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton();
|
||||||
});
|
});
|
||||||
|
chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
|
||||||
|
if (result.hideInfoButtonPlayerControls != undefined) {
|
||||||
|
hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
});
|
||||||
|
chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
|
||||||
|
if (result.hideDeleteButtonPlayerControls != undefined) {
|
||||||
|
hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sponsorsLookup(id) {
|
function sponsorsLookup(id) {
|
||||||
@@ -155,16 +237,22 @@ function sponsorsLookup(id) {
|
|||||||
function sponsorCheck(sponsorTimes) { // Video skipping
|
function sponsorCheck(sponsorTimes) { // Video skipping
|
||||||
//see if any sponsor start time was just passed
|
//see if any sponsor start time was just passed
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
//the sponsor time is in between these times, skip it
|
//this means part of the video was just skipped
|
||||||
//if the time difference is more than 1 second, than the there was probably a skip in time,
|
if (Math.abs(v.currentTime - lastTime) > 1 && lastTime != -1) {
|
||||||
// and it's not due to playback
|
//make lastTime as if the video was playing normally
|
||||||
//also check if the last time skipped to is not too close to now, to make sure not to get too many
|
lastTime = v.currentTime - 0.0001;
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentTime = Date.now();
|
||||||
|
|
||||||
|
//If the sponsor time is in between these times, skip it
|
||||||
|
//Checks if the last time skipped to is not too close to now, to make sure not to get too many
|
||||||
// sponsor times in a row (from one troll)
|
// sponsor times in a row (from one troll)
|
||||||
if (Math.abs(v.currentTime - lastTime) < 1 && sponsorTimes[i][0] >= lastTime && sponsorTimes[i][0] <= v.currentTime &&
|
//the last term makes 0 second start times possible
|
||||||
(lastTimeSkippedTo == -1 || Math.abs(v.currentTime - lastTimeSkippedTo) > 1)) {
|
if ((Math.abs(v.currentTime - sponsorTimes[i][0]) < 0.3 && sponsorTimes[i][0] >= lastTime && sponsorTimes[i][0] <= v.currentTime
|
||||||
|
&& (lastUnixTimeSkipped == -1 || currentTime - lastUnixTimeSkipped > 500)) || (lastTime == -1 && sponsorTimes[i][0] == 0)) {
|
||||||
//skip it
|
//skip it
|
||||||
v.currentTime = sponsorTimes[i][1];
|
v.currentTime = sponsorTimes[i][1];
|
||||||
lastTimeSkippedTo = sponsorTimes[i][1];
|
|
||||||
|
|
||||||
lastSponsorTimeSkipped = sponsorTimes[i][0];
|
lastSponsorTimeSkipped = sponsorTimes[i][0];
|
||||||
|
|
||||||
@@ -172,19 +260,25 @@ function sponsorCheck(sponsorTimes) { // Video skipping
|
|||||||
lastSponsorTimeSkippedUUID = currentUUID;
|
lastSponsorTimeSkippedUUID = currentUUID;
|
||||||
|
|
||||||
//send out the message saying that a sponsor message was skipped
|
//send out the message saying that a sponsor message was skipped
|
||||||
openSkipNotice();
|
openSkipNotice(currentUUID);
|
||||||
|
|
||||||
setTimeout(() => closeSkipNotice(currentUUID), 7000);
|
setTimeout(() => closeSkipNotice(currentUUID), 7000);
|
||||||
|
|
||||||
//send telemetry that a this sponsor was skipped happened
|
//send telemetry that a this sponsor was skipped happened
|
||||||
sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
if (trackViewCount) {
|
||||||
|
sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastTime = v.currentTime;
|
|
||||||
|
//don't keep track until they are loaded in
|
||||||
|
if (sponsorTimes.length > 0) {
|
||||||
|
lastTime = v.currentTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function goBackToPreviousTime(UUID) {
|
function goBackToPreviousTime(UUID) {
|
||||||
if (sponsorTimes != undefined) {
|
if (sponsorTimes != null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//add a tiny bit of time to make sure it is not skipped again
|
||||||
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
|
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
|
||||||
|
|
||||||
@@ -225,30 +319,49 @@ function removePlayerControlsButton() {
|
|||||||
|
|
||||||
//adds or removes the player controls button to what it should be
|
//adds or removes the player controls button to what it should be
|
||||||
function updateVisibilityOfPlayerControlsButton() {
|
function updateVisibilityOfPlayerControlsButton() {
|
||||||
|
addPlayerControlsButton();
|
||||||
|
addInfoButton();
|
||||||
|
addDeleteButton();
|
||||||
|
addSubmitButton();
|
||||||
if (hideVideoPlayerControls) {
|
if (hideVideoPlayerControls) {
|
||||||
removePlayerControlsButton();
|
removePlayerControlsButton();
|
||||||
} else {
|
}
|
||||||
addPlayerControlsButton();
|
if (hideInfoButtonPlayerControls) {
|
||||||
addSubmitButton();
|
document.getElementById("infoButton").style.display = "none";
|
||||||
|
}
|
||||||
|
if (hideDeleteButtonPlayerControls) {
|
||||||
|
document.getElementById("deleteButton").style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startSponsorClicked() {
|
function startSponsorClicked() {
|
||||||
|
//it can't update to this info yet
|
||||||
|
closeInfoMenu();
|
||||||
|
|
||||||
toggleStartSponsorButton();
|
toggleStartSponsorButton();
|
||||||
|
|
||||||
//send back current time with message
|
//send back current time with message
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
message: "addSponsorTime",
|
message: "addSponsorTime",
|
||||||
time: v.currentTime
|
time: v.currentTime,
|
||||||
|
videoID: getYouTubeVideoID(document.URL)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||||
|
//if it isn't visible, there is no data
|
||||||
|
if (uploadButtonVisible && !hideDeleteButtonPlayerControls) {
|
||||||
|
document.getElementById("deleteButton").style.display = "unset";
|
||||||
|
} else {
|
||||||
|
document.getElementById("deleteButton").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
if (showStartSponsor) {
|
if (showStartSponsor) {
|
||||||
showingStartSponsor = true;
|
showingStartSponsor = true;
|
||||||
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
|
document.getElementById("startSponsorButton").setAttribute("title", "Sponsor Starts Now");
|
||||||
|
|
||||||
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible) {
|
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) {
|
||||||
document.getElementById("submitButton").style.display = "unset";
|
document.getElementById("submitButton").style.display = "unset";
|
||||||
} else if (!uploadButtonVisible) {
|
} else if (!uploadButtonVisible) {
|
||||||
//disable submit button
|
//disable submit button
|
||||||
@@ -257,6 +370,7 @@ function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||||||
} else {
|
} else {
|
||||||
showingStartSponsor = false;
|
showingStartSponsor = false;
|
||||||
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
|
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
|
||||||
|
document.getElementById("startSponsorButton").setAttribute("title", "Sponsor Ends Now");
|
||||||
|
|
||||||
//disable submit button
|
//disable submit button
|
||||||
document.getElementById("submitButton").style.display = "none";
|
document.getElementById("submitButton").style.display = "none";
|
||||||
@@ -267,6 +381,60 @@ function toggleStartSponsorButton() {
|
|||||||
changeStartSponsorButton(!showingStartSponsor, true);
|
changeStartSponsorButton(!showingStartSponsor, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//shows the info button on the video player
|
||||||
|
function addInfoButton() {
|
||||||
|
if (document.getElementById("infoButton") != null) {
|
||||||
|
//it's already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//make a submit button
|
||||||
|
let infoButton = document.createElement("button");
|
||||||
|
infoButton.id = "infoButton";
|
||||||
|
infoButton.className = "ytp-button playerButton";
|
||||||
|
infoButton.setAttribute("title", "Open SponsorBlock Popup");
|
||||||
|
infoButton.addEventListener("click", openInfoMenu);
|
||||||
|
|
||||||
|
let infoImage = document.createElement("img");
|
||||||
|
infoImage.id = "infoButtonImage";
|
||||||
|
infoImage.className = "playerButtonImage";
|
||||||
|
infoImage.src = chrome.extension.getURL("icons/PlayerInfoIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
//add the image to the button
|
||||||
|
infoButton.appendChild(infoImage);
|
||||||
|
|
||||||
|
let referenceNode = document.getElementsByClassName("ytp-right-controls")[0];
|
||||||
|
referenceNode.prepend(infoButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
//shows the delete button on the video player
|
||||||
|
function addDeleteButton() {
|
||||||
|
if (document.getElementById("deleteButton") != null) {
|
||||||
|
//it's already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//make a submit button
|
||||||
|
let deleteButton = document.createElement("button");
|
||||||
|
deleteButton.id = "deleteButton";
|
||||||
|
deleteButton.className = "ytp-button playerButton";
|
||||||
|
deleteButton.setAttribute("title", "Clear Sponsor Times");
|
||||||
|
deleteButton.addEventListener("click", clearSponsorTimes);
|
||||||
|
//hide it at the start
|
||||||
|
deleteButton.style.display = "none";
|
||||||
|
|
||||||
|
let deleteImage = document.createElement("img");
|
||||||
|
deleteImage.id = "deleteButtonImage";
|
||||||
|
deleteImage.className = "playerButtonImage";
|
||||||
|
deleteImage.src = chrome.extension.getURL("icons/PlayerDeleteIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
//add the image to the button
|
||||||
|
deleteButton.appendChild(deleteImage);
|
||||||
|
|
||||||
|
let referenceNode = document.getElementsByClassName("ytp-right-controls")[0];
|
||||||
|
referenceNode.prepend(deleteButton);
|
||||||
|
}
|
||||||
|
|
||||||
//shows the submit button on the video player
|
//shows the submit button on the video player
|
||||||
function addSubmitButton() {
|
function addSubmitButton() {
|
||||||
if (document.getElementById("submitButton") != null) {
|
if (document.getElementById("submitButton") != null) {
|
||||||
@@ -295,13 +463,109 @@ function addSubmitButton() {
|
|||||||
referenceNode.prepend(submitButton);
|
referenceNode.prepend(submitButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openInfoMenu() {
|
||||||
|
if (document.getElementById("sponsorBlockPopupContainer") != null) {
|
||||||
|
//it's already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
popupInitialised = false;
|
||||||
|
|
||||||
|
//hide info button
|
||||||
|
document.getElementById("infoButton").style.display = "none";
|
||||||
|
|
||||||
|
let popup = document.createElement("div");
|
||||||
|
popup.id = "sponsorBlockPopupContainer";
|
||||||
|
|
||||||
|
let popupFrame = document.createElement("iframe");
|
||||||
|
popupFrame.id = "sponsorBlockPopupFrame"
|
||||||
|
popupFrame.src = chrome.extension.getURL("popup.html");
|
||||||
|
popupFrame.className = "popup";
|
||||||
|
|
||||||
|
//close button
|
||||||
|
let closeButton = document.createElement("div");
|
||||||
|
closeButton.innerText = "Close Popup";
|
||||||
|
closeButton.classList = "smallLink";
|
||||||
|
closeButton.setAttribute("align", "center");
|
||||||
|
closeButton.addEventListener("click", closeInfoMenu);
|
||||||
|
|
||||||
|
popup.appendChild(closeButton);
|
||||||
|
popup.appendChild(popupFrame);
|
||||||
|
|
||||||
|
let parentNode = document.getElementById("secondary");
|
||||||
|
if (parentNode == null) {
|
||||||
|
//old youtube theme
|
||||||
|
parentNode = document.getElementById("watch7-sidebar-contents");
|
||||||
|
}
|
||||||
|
|
||||||
|
parentNode.prepend(popup);
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeInfoMenu() {
|
||||||
|
let popup = document.getElementById("sponsorBlockPopupContainer");
|
||||||
|
if (popup != null) {
|
||||||
|
popup.remove();
|
||||||
|
|
||||||
|
//show info button
|
||||||
|
document.getElementById("infoButton").style.display = "unset";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSponsorTimes() {
|
||||||
|
//it can't update to this info yet
|
||||||
|
closeInfoMenu();
|
||||||
|
|
||||||
|
let currentVideoID = getYouTubeVideoID(document.URL);
|
||||||
|
|
||||||
|
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||||
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
|
let confirmMessage = "Are you sure you want to clear this?\n\n" + getSponsorTimesMessage(sponsorTimes);
|
||||||
|
confirmMessage += "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
|
||||||
|
if(!confirm(confirmMessage)) return;
|
||||||
|
|
||||||
|
//clear the sponsor times
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||||
|
|
||||||
|
//set buttons to be correct
|
||||||
|
changeStartSponsorButton(true, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Opens the notice that tells the user that a sponsor was just skipped
|
//Opens the notice that tells the user that a sponsor was just skipped
|
||||||
function openSkipNotice(){
|
function openSkipNotice(UUID){
|
||||||
if (dontShowNotice) {
|
if (dontShowNotice) {
|
||||||
//don't show, return
|
//don't show, return
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if page is loaded yet (for 0 second sponsors, the page might not be loaded yet)
|
||||||
|
//it looks for the view count div and sees if it is full yet
|
||||||
|
//querySelectorAll is being used like findElementById for multiple objects, because for
|
||||||
|
//some reason YouTube has put more than one object with one ID.
|
||||||
|
let viewCountNode = document.querySelectorAll("#count");
|
||||||
|
//check to see if the length is over zero, otherwise it's a different YouTube theme probably
|
||||||
|
if (viewCountNode.length > 0) {
|
||||||
|
//check if any of these have text
|
||||||
|
let viewCountVisible = false;
|
||||||
|
for (let i = 0; i < viewCountNode.length; i++) {
|
||||||
|
if (viewCountNode[i].innerText != null) {
|
||||||
|
viewCountVisible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!viewCountVisible) {
|
||||||
|
//this is the new YouTube layout and it is still loading
|
||||||
|
//wait a bit for opening the notice
|
||||||
|
setTimeout(() => openSkipNotice(UUID), 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let amountOfPreviousNotices = document.getElementsByClassName("sponsorSkipNotice").length;
|
let amountOfPreviousNotices = document.getElementsByClassName("sponsorSkipNotice").length;
|
||||||
|
|
||||||
if (amountOfPreviousNotices > 0) {
|
if (amountOfPreviousNotices > 0) {
|
||||||
@@ -311,45 +575,43 @@ function openSkipNotice(){
|
|||||||
previousNotice.classList.add("secondSkipNotice")
|
previousNotice.classList.add("secondSkipNotice")
|
||||||
}
|
}
|
||||||
|
|
||||||
let UUID = lastSponsorTimeSkippedUUID;
|
|
||||||
|
|
||||||
let noticeElement = document.createElement("div");
|
let noticeElement = document.createElement("div");
|
||||||
//what sponsor time this is about
|
//what sponsor time this is about
|
||||||
noticeElement.id = "sponsorSkipNotice" + lastSponsorTimeSkippedUUID;
|
noticeElement.id = "sponsorSkipNotice" + UUID;
|
||||||
noticeElement.classList.add("sponsorSkipObject");
|
noticeElement.classList.add("sponsorSkipObject");
|
||||||
noticeElement.classList.add("sponsorSkipNotice");
|
noticeElement.classList.add("sponsorSkipNotice");
|
||||||
noticeElement.style.zIndex = 1 + amountOfPreviousNotices;
|
noticeElement.style.zIndex = 5 + amountOfPreviousNotices;
|
||||||
|
|
||||||
let logoElement = document.createElement("img");
|
let logoElement = document.createElement("img");
|
||||||
logoElement.id = "sponsorSkipLogo" + lastSponsorTimeSkippedUUID;
|
logoElement.id = "sponsorSkipLogo" + UUID;
|
||||||
logoElement.className = "sponsorSkipLogo";
|
logoElement.className = "sponsorSkipLogo";
|
||||||
logoElement.src = chrome.extension.getURL("icons/LogoSponsorBlocker256px.png");
|
logoElement.src = chrome.extension.getURL("icons/LogoSponsorBlocker256px.png");
|
||||||
|
|
||||||
let noticeMessage = document.createElement("div");
|
let noticeMessage = document.createElement("div");
|
||||||
noticeMessage.id = "sponsorSkipMessage" + lastSponsorTimeSkippedUUID;
|
noticeMessage.id = "sponsorSkipMessage" + UUID;
|
||||||
noticeMessage.classList.add("sponsorSkipMessage");
|
noticeMessage.classList.add("sponsorSkipMessage");
|
||||||
noticeMessage.classList.add("sponsorSkipObject");
|
noticeMessage.classList.add("sponsorSkipObject");
|
||||||
noticeMessage.innerText = "Hey, you just skipped a sponsor!";
|
noticeMessage.innerText = "Hey, you just skipped a sponsor!";
|
||||||
|
|
||||||
let noticeInfo = document.createElement("p");
|
let noticeInfo = document.createElement("p");
|
||||||
noticeInfo.id = "sponsorSkipInfo" + lastSponsorTimeSkippedUUID;
|
noticeInfo.id = "sponsorSkipInfo" + UUID;
|
||||||
noticeInfo.classList.add("sponsorSkipInfo");
|
noticeInfo.classList.add("sponsorSkipInfo");
|
||||||
noticeInfo.classList.add("sponsorSkipObject");
|
noticeInfo.classList.add("sponsorSkipObject");
|
||||||
noticeInfo.innerText = "This message will disapear in 7 seconds";
|
noticeInfo.innerText = "This message will disapear in 7 seconds";
|
||||||
|
|
||||||
//thumbs up and down buttons
|
//thumbs up and down buttons
|
||||||
let voteButtonsContainer = document.createElement("div");
|
let voteButtonsContainer = document.createElement("div");
|
||||||
voteButtonsContainer.id = "sponsorTimesVoteButtonsContainer" + lastSponsorTimeSkippedUUID;
|
voteButtonsContainer.id = "sponsorTimesVoteButtonsContainer" + UUID;
|
||||||
voteButtonsContainer.setAttribute("align", "center");
|
voteButtonsContainer.setAttribute("align", "center");
|
||||||
|
|
||||||
let upvoteButton = document.createElement("img");
|
let upvoteButton = document.createElement("img");
|
||||||
upvoteButton.id = "sponsorTimesUpvoteButtonsContainer" + lastSponsorTimeSkippedUUID;
|
upvoteButton.id = "sponsorTimesUpvoteButtonsContainer" + UUID;
|
||||||
upvoteButton.className = "sponsorSkipObject voteButton";
|
upvoteButton.className = "sponsorSkipObject voteButton";
|
||||||
upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
|
upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
|
||||||
upvoteButton.addEventListener("click", () => vote(1, UUID));
|
upvoteButton.addEventListener("click", () => vote(1, UUID));
|
||||||
|
|
||||||
let downvoteButton = document.createElement("img");
|
let downvoteButton = document.createElement("img");
|
||||||
downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + lastSponsorTimeSkippedUUID;
|
downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + UUID;
|
||||||
downvoteButton.className = "sponsorSkipObject voteButton";
|
downvoteButton.className = "sponsorSkipObject voteButton";
|
||||||
downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
|
downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
|
||||||
downvoteButton.addEventListener("click", () => vote(0, UUID));
|
downvoteButton.addEventListener("click", () => vote(0, UUID));
|
||||||
@@ -479,8 +741,13 @@ function vote(type, UUID) {
|
|||||||
//failure: duplicate vote
|
//failure: duplicate vote
|
||||||
addLoadingInfo("It seems you've already voted before", UUID)
|
addLoadingInfo("It seems you've already voted before", UUID)
|
||||||
} else if (response.successType == -1) {
|
} else if (response.successType == -1) {
|
||||||
//failure: duplicate vote
|
if (response.statusCode == 502) {
|
||||||
addLoadingInfo("A connection error has occured.", UUID)
|
addLoadingInfo("It seems the sever is down. Contact the dev immediately.", UUID)
|
||||||
|
} else {
|
||||||
|
//failure: unknown error
|
||||||
|
addLoadingInfo("A connection error has occured. Error code: " + response.statusCode, UUID)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -510,20 +777,47 @@ function dontShowNoticeAgain() {
|
|||||||
closeAllSkipNotices();
|
closeAllSkipNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sponsorMessageStarted() {
|
function sponsorMessageStarted(callback) {
|
||||||
let v = document.querySelector('video');
|
let v = document.querySelector('video');
|
||||||
|
|
||||||
//send back current time
|
//send back current time
|
||||||
chrome.runtime.sendMessage({
|
callback({
|
||||||
message: "time",
|
|
||||||
time: v.currentTime
|
time: v.currentTime
|
||||||
});
|
})
|
||||||
|
|
||||||
//update button
|
//update button
|
||||||
toggleStartSponsorButton();
|
toggleStartSponsorButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitSponsorTimes() {
|
function submitSponsorTimes() {
|
||||||
|
if (document.getElementById("submitButton").style.display == "none") {
|
||||||
|
//don't submit, not ready
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//it can't update to this info yet
|
||||||
|
closeInfoMenu();
|
||||||
|
|
||||||
|
let currentVideoID = getYouTubeVideoID(document.URL);
|
||||||
|
|
||||||
|
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||||
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
|
let confirmMessage = "Are you sure you want to submit this?\n\n" + getSponsorTimesMessage(sponsorTimes);
|
||||||
|
confirmMessage += "\n\nTo edit or delete values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
|
||||||
|
if(!confirm(confirmMessage)) return;
|
||||||
|
|
||||||
|
sendSubmitMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//send the message to the background js
|
||||||
|
//called after all the checks have been made that it's okay to do so
|
||||||
|
function sendSubmitMessage(){
|
||||||
//add loading animation
|
//add loading animation
|
||||||
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
||||||
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
||||||
@@ -554,11 +848,59 @@ function submitSponsorTimes() {
|
|||||||
//show that the upload failed
|
//show that the upload failed
|
||||||
document.getElementById("submitButton").style.animation = "unset";
|
document.getElementById("submitButton").style.animation = "unset";
|
||||||
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
|
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
if(response.statusCode == 400) {
|
||||||
|
alert("Server said this request was invalid");
|
||||||
|
} else if(response.statusCode == 429) {
|
||||||
|
alert("You have submitted too many sponsor times for this one video, are you sure there are this many?");
|
||||||
|
} else if(response.statusCode == 409) {
|
||||||
|
alert("This has already been submitted before");
|
||||||
|
} else if(response.statusCode == 502) {
|
||||||
|
alert("It seems the server is down. Contact the dev to inform them. Error code " + response.statusCode);
|
||||||
|
} else {
|
||||||
|
alert("There was an error submitting your sponsor times, please try again later. Error code " + response.statusCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the message that visually displays the video times
|
||||||
|
function getSponsorTimesMessage(sponsorTimes) {
|
||||||
|
let sponsorTimesMessage = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
|
for (let s = 0; s < sponsorTimes[i].length; s++) {
|
||||||
|
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
|
||||||
|
//if this is an end time
|
||||||
|
if (s == 1) {
|
||||||
|
timeMessage = " to " + timeMessage;
|
||||||
|
} else if (i > 0) {
|
||||||
|
//add commas if necessary
|
||||||
|
timeMessage = ", " + timeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
sponsorTimesMessage += timeMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sponsorTimesMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
//converts time in seconds to minutes:seconds
|
||||||
|
function getFormattedTime(seconds) {
|
||||||
|
let minutes = Math.floor(seconds / 60);
|
||||||
|
let secondsDisplay = Math.round(seconds - minutes * 60);
|
||||||
|
if (secondsDisplay < 10) {
|
||||||
|
//add a zero
|
||||||
|
secondsDisplay = "0" + secondsDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
let formatted = minutes+ ":" + secondsDisplay;
|
||||||
|
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
function sendRequestToServer(type, address, callback) {
|
function sendRequestToServer(type, address, callback) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
@@ -600,5 +942,6 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
|||||||
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
var id = new URL(url).searchParams.get("v");
|
||||||
}
|
return (match && match[7].length == 11) ? id : false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock - YouTube Sponsorship Blocker",
|
"name": "SponsorBlock - YouTube Sponsorship Blocker",
|
||||||
"short_name": "SponsorBlock",
|
"short_name": "SponsorBlock",
|
||||||
"version": "1.0.1",
|
"version": "1.0.12",
|
||||||
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,10 @@
|
|||||||
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
||||||
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
||||||
"icons/upvote.png",
|
"icons/upvote.png",
|
||||||
"icons/downvote.png"
|
"icons/downvote.png",
|
||||||
|
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
||||||
|
"popup.html"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
|
|||||||
BIN
icons/PlayerDeleteIconSponsorBlocker256px.png
Normal file
BIN
icons/PlayerDeleteIconSponsorBlocker256px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
icons/PlayerInfoIconSponsorBlocker256px.png
Normal file
BIN
icons/PlayerInfoIconSponsorBlocker256px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock - YouTube Sponsorship Blocker",
|
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||||
"short_name": "SponsorBlock",
|
"short_name": "SponsorBlock",
|
||||||
"version": "1.0.1",
|
"version": "1.0.16",
|
||||||
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,10 @@
|
|||||||
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
||||||
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
||||||
"icons/upvote.png",
|
"icons/upvote.png",
|
||||||
"icons/downvote.png"
|
"icons/downvote.png",
|
||||||
|
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
||||||
|
"popup.html"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
|
|||||||
24
popup.css
24
popup.css
@@ -8,7 +8,7 @@ h1 {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
width: 300px;
|
min-width: 300px;
|
||||||
background-color: #ffd9d9;
|
background-color: #ffd9d9;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +25,28 @@ body {
|
|||||||
filter: brightness(80%);
|
filter: brightness(80%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#discordButtonContainer {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sponsorTime {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.smallLink {
|
||||||
|
font-size: 10px;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mediumLink {
|
||||||
|
font-size: 15px;
|
||||||
|
padding-left: 15px;
|
||||||
|
padding-right: 15px;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.greenButton {
|
.greenButton {
|
||||||
background-color:#ec1c1c;
|
background-color:#ec1c1c;
|
||||||
-moz-border-radius:28px;
|
-moz-border-radius:28px;
|
||||||
|
|||||||
64
popup.html
64
popup.html
@@ -71,7 +71,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<button id="sponsorStart" class="greenButton">Sponsorship Starts Now</button>
|
<button id="sponsorStart" class="greenButton">Sponsorship Starts Now</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<sub>Hint: Press the semicolon key while focused on a video report the start/end of a sponsor and quote to submit.</sub>
|
||||||
|
|
||||||
<div id="submissionSection" style="display: none">
|
<div id="submissionSection" style="display: none">
|
||||||
<h3>Latest Sponsor Message Times Chosen</h3>
|
<h3>Latest Sponsor Message Times Chosen</h3>
|
||||||
<b>
|
<b>
|
||||||
@@ -98,6 +100,20 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="discordButtonContainer" style="display: none">
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<a href="https://discord.gg/QnmVMpU" target="_blank"><img src="https://www.logolynx.com/images/logolynx/1b/1bcc0f0aefe71b2c8ce66ffe8645d365.png" height="32px"/></a>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
Come join the official discord server to give suggestions and feedback!
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<span id="hideDiscordButton" class="smallLink">Hide this</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="optionsButtonContainer">
|
<div id="optionsButtonContainer">
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
@@ -110,12 +126,52 @@
|
|||||||
|
|
||||||
<h3>Options</h3>
|
<h3>Options</h3>
|
||||||
|
|
||||||
<button id="hideVideoPlayerControls" class="warningButton">Hide Button On YouTube Player</button>
|
<button id="hideVideoPlayerControls" class="warningButton">Hide Buttons On YouTube Player</button>
|
||||||
<button id="showVideoPlayerControls" style="display: none" class="warningButton">Show Button On YouTube Player</button>
|
<button id="showVideoPlayerControls" style="display: none" class="warningButton">Show Buttons On YouTube Player</button>
|
||||||
|
<br/>
|
||||||
|
<sub>
|
||||||
|
This hides the buttons that appear on the YouTube player to submit sponsors. I can see this being annoying for some
|
||||||
|
people. Instead of using the button there, this popup can be used to submit sponsors. To hide the notice that appears,
|
||||||
|
use the button that appears on the notice saying "Don't show this again". You can always enable these settings again
|
||||||
|
later.
|
||||||
|
</sub>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<button id="hideInfoButtonPlayerControls" class="warningButton">Hide Info Button On YouTube Player</button>
|
||||||
|
<button id="showInfoButtonPlayerControls" style="display: none" class="warningButton">Show Info Button On YouTube Player</button>
|
||||||
|
<br/>
|
||||||
|
<sub>
|
||||||
|
This is the button that opens up a popup in the YouTube page.
|
||||||
|
</sub>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<button id="hideDeleteButtonPlayerControls" class="warningButton">Hide Delete Button On YouTube Player</button>
|
||||||
|
<button id="showDeleteButtonPlayerControls" style="display: none" class="warningButton">Show Delete Button On YouTube Player</button>
|
||||||
|
<br/>
|
||||||
|
<sub>
|
||||||
|
This is the button that allows you to clear all sponsors on the YouTube player.
|
||||||
|
</sub>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<button id="disableSponsorViewTracking" class="warningButton">Disable Sponsor View Tracking</button>
|
||||||
|
<button id="enableSponsorViewTracking" style="display: none" class="warningButton">Enable Sponsor View Tracking</button>
|
||||||
|
<br/>
|
||||||
|
<sub>
|
||||||
|
This feature tracks which sponsors you have skipped to let users know how much their submission has helped others and
|
||||||
|
used as a metric along with upvotes to ensure that spam doesn't get into the database. The extension sends a message
|
||||||
|
to the server each time you skip a sponsor. Hopefully most people don't change this setting so that the view numbers
|
||||||
|
are accurate. :)
|
||||||
|
</sub>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<button id="showNoticeAgain" style="display: none" class="dangerButton">Show Notice Again</button>
|
<button id="showNoticeAgain" style="display: none" class="dangerButton">Show Notice Again</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
534
popup.js
534
popup.js
@@ -1,12 +1,50 @@
|
|||||||
|
|
||||||
|
// References
|
||||||
|
var SB = {};
|
||||||
|
|
||||||
|
SB.sponsorStart = document.getElementById("sponsorStart");
|
||||||
|
SB.clearTimes = document.getElementById("clearTimes");
|
||||||
|
SB.submitTimes = document.getElementById("submitTimes");
|
||||||
|
SB.showNoticeAgain = document.getElementById("showNoticeAgain");
|
||||||
|
SB.hideVideoPlayerControls = document.getElementById("hideVideoPlayerControls");
|
||||||
|
SB.showVideoPlayerControls = document.getElementById("showVideoPlayerControls");
|
||||||
|
SB.hideInfoButtonPlayerControls = document.getElementById("hideInfoButtonPlayerControls");
|
||||||
|
SB.showInfoButtonPlayerControls = document.getElementById("showInfoButtonPlayerControls");
|
||||||
|
SB.hideDeleteButtonPlayerControls = document.getElementById("hideDeleteButtonPlayerControls");
|
||||||
|
SB.showDeleteButtonPlayerControls = document.getElementById("showDeleteButtonPlayerControls");
|
||||||
|
SB.disableSponsorViewTracking = document.getElementById("disableSponsorViewTracking");
|
||||||
|
SB.enableSponsorViewTracking = document.getElementById("enableSponsorViewTracking");
|
||||||
|
SB.optionsButton = document.getElementById("optionsButton");
|
||||||
|
SB.reportAnIssue = document.getElementById("reportAnIssue");
|
||||||
|
// sponsorTimesContributions
|
||||||
|
SB.sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
|
||||||
|
SB.sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
|
||||||
|
SB.sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
|
||||||
|
// sponsorTimesViewsDisplay
|
||||||
|
SB.sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsDisplayContainer");
|
||||||
|
SB.sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplayDisplay");
|
||||||
|
SB.sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayDisplayEndWord");
|
||||||
|
// discordButtons
|
||||||
|
SB.discordButtonContainer = document.getElementById("discordButtonContainer");
|
||||||
|
SB.hideDiscordButton = document.getElementById("hideDiscordButton");
|
||||||
|
|
||||||
//setup click listeners
|
//setup click listeners
|
||||||
document.getElementById("sponsorStart").addEventListener("click", sendSponsorStartMessage);
|
SB.sponsorStart.addEventListener("click", sendSponsorStartMessage);
|
||||||
document.getElementById("clearTimes").addEventListener("click", clearTimes);
|
SB.clearTimes.addEventListener("click", clearTimes);
|
||||||
document.getElementById("submitTimes").addEventListener("click", submitTimes);
|
SB.submitTimes.addEventListener("click", submitTimes);
|
||||||
document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain);
|
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
|
||||||
document.getElementById("hideVideoPlayerControls").addEventListener("click", hideVideoPlayerControls);
|
SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
|
||||||
document.getElementById("showVideoPlayerControls").addEventListener("click", showVideoPlayerControls);
|
SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
|
||||||
document.getElementById("optionsButton").addEventListener("click", openOptions);
|
SB.hideInfoButtonPlayerControls.addEventListener("click", hideInfoButtonPlayerControls);
|
||||||
document.getElementById("reportAnIssue").addEventListener("click", reportAnIssue);
|
SB.showInfoButtonPlayerControls.addEventListener("click", showInfoButtonPlayerControls);
|
||||||
|
SB.hideDeleteButtonPlayerControls.addEventListener("click", hideDeleteButtonPlayerControls);
|
||||||
|
SB.showDeleteButtonPlayerControls.addEventListener("click", showDeleteButtonPlayerControls);
|
||||||
|
SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
|
||||||
|
SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
|
||||||
|
SB.optionsButton.addEventListener("click", openOptions);
|
||||||
|
SB.reportAnIssue.addEventListener("click", reportAnIssue);
|
||||||
|
SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
|
||||||
|
|
||||||
|
|
||||||
//if true, the button now selects the end time
|
//if true, the button now selects the end time
|
||||||
var startTimeChosen = false;
|
var startTimeChosen = false;
|
||||||
@@ -20,38 +58,77 @@ var currentVideoID = null;
|
|||||||
//is this a YouTube tab?
|
//is this a YouTube tab?
|
||||||
var isYouTubeTab = false;
|
var isYouTubeTab = false;
|
||||||
|
|
||||||
|
//see if discord link can be shown
|
||||||
|
chrome.storage.sync.get(["hideDiscordLink"], function(result) {
|
||||||
|
let hideDiscordLink = result.hideDiscordLink;
|
||||||
|
if (hideDiscordLink == undefined || !hideDiscordLink) {
|
||||||
|
chrome.storage.sync.get(["hideDiscordLaunches"], function(result) {
|
||||||
|
let hideDiscordLaunches = result.hideDiscordLaunches;
|
||||||
|
//only if less than 5 launches
|
||||||
|
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
|
||||||
|
SB.discordButtonContainer.style.display = null;
|
||||||
|
|
||||||
|
if (hideDiscordLaunches == undefined) {
|
||||||
|
hideDiscordButton = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.storage.sync.set({"hideDiscordLaunches": hideDiscordButton + 1});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//if the don't show notice again variable is true, an option to
|
//if the don't show notice again variable is true, an option to
|
||||||
// disable should be available
|
// disable should be available
|
||||||
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
||||||
let dontShowNoticeAgain = result.dontShowNoticeAgain;
|
let dontShowNoticeAgain = result.dontShowNoticeAgain;
|
||||||
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
|
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
|
||||||
document.getElementById("showNoticeAgain").style.display = "unset";
|
SB.showNoticeAgain.style.display = "unset";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//show proper video player controls option
|
//show proper video player controls options
|
||||||
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
||||||
let hideVideoPlayerControls = result.hideVideoPlayerControls;
|
let hideVideoPlayerControls = result.hideVideoPlayerControls;
|
||||||
if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
|
if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "none";
|
SB.hideVideoPlayerControls.style.display = "none";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "unset";
|
SB.showVideoPlayerControls.style.display = "unset";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
|
||||||
|
let hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
|
||||||
|
if (hideInfoButtonPlayerControls != undefined && hideInfoButtonPlayerControls) {
|
||||||
|
SB.hideInfoButtonPlayerControls.style.display = "none";
|
||||||
|
SB.showInfoButtonPlayerControls.style.display = "unset";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
|
||||||
|
let hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
|
||||||
|
if (hideDeleteButtonPlayerControls != undefined && hideDeleteButtonPlayerControls) {
|
||||||
|
SB.hideDeleteButtonPlayerControls.style.display = "none";
|
||||||
|
SB.showDeleteButtonPlayerControls.style.display = "unset";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//show proper tracking option
|
||||||
|
chrome.storage.sync.get(["trackViewCount"], function(result) {
|
||||||
|
let trackViewCount = result.trackViewCount;
|
||||||
|
if (trackViewCount != undefined && !trackViewCount) {
|
||||||
|
SB.disableSponsorViewTracking.style.display = "none";
|
||||||
|
SB.enableSponsorViewTracking.style.display = "unset";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//get the amount of times this user has contributed and display it to thank them
|
//get the amount of times this user has contributed and display it to thank them
|
||||||
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
||||||
if (result.sponsorTimesContributed != undefined) {
|
if (result.sponsorTimesContributed != undefined) {
|
||||||
let sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
|
|
||||||
let sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
|
|
||||||
let sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
|
|
||||||
|
|
||||||
if (result.sponsorTimesContributed > 1) {
|
if (result.sponsorTimesContributed > 1) {
|
||||||
sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
|
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
|
||||||
} else {
|
} else {
|
||||||
sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
|
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
|
||||||
}
|
}
|
||||||
sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
||||||
sponsorTimesContributionsContainer.style.display = "unset";
|
SB.sponsorTimesContributionsContainer.style.display = "unset";
|
||||||
|
|
||||||
//get the userID
|
//get the userID
|
||||||
chrome.storage.sync.get(["userID"], function(result) {
|
chrome.storage.sync.get(["userID"], function(result) {
|
||||||
@@ -62,19 +139,14 @@ chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
|||||||
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
||||||
|
|
||||||
if (viewCount != 0) {
|
if (viewCount != 0) {
|
||||||
let sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsContainer");
|
|
||||||
let sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplay");
|
|
||||||
let sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayEndWord");
|
|
||||||
|
|
||||||
if (viewCount > 1) {
|
if (viewCount > 1) {
|
||||||
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
|
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
|
||||||
} else {
|
} else {
|
||||||
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
|
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
|
||||||
}
|
}
|
||||||
sponsorTimesViewsDisplay.innerText = viewCount;
|
SB.sponsorTimesViewsDisplay.innerText = viewCount;
|
||||||
sponsorTimesViewsContainer.style.display = "unset";
|
SB.sponsorTimesViewsContainer.style.display = "unset";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -106,7 +178,7 @@ function loadTabData(tabs) {
|
|||||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||||
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimes = sponsorTimesStorage;
|
sponsorTimes = sponsorTimesStorage;
|
||||||
@@ -170,40 +242,47 @@ function sendSponsorStartMessage() {
|
|||||||
}, tabs => {
|
}, tabs => {
|
||||||
chrome.tabs.sendMessage(
|
chrome.tabs.sendMessage(
|
||||||
tabs[0].id,
|
tabs[0].id,
|
||||||
{from: 'popup', message: 'sponsorStart'}
|
{from: 'popup', message: 'sponsorStart'},
|
||||||
|
startSponsorCallback
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
function startSponsorCallback(response) {
|
||||||
if (request.message == "time") {
|
let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0);
|
||||||
let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0);
|
|
||||||
|
|
||||||
if (sponsorTimes[sponsorTimesIndex] == undefined) {
|
if (sponsorTimes[sponsorTimesIndex] == undefined) {
|
||||||
sponsorTimes[sponsorTimesIndex] = [];
|
sponsorTimes[sponsorTimesIndex] = [];
|
||||||
}
|
|
||||||
|
|
||||||
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = request.time;
|
|
||||||
|
|
||||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
|
||||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
|
||||||
|
|
||||||
updateStartTimeChosen();
|
|
||||||
|
|
||||||
//display video times on screen
|
|
||||||
displaySponsorTimes();
|
|
||||||
|
|
||||||
//show submission section
|
|
||||||
document.getElementById("submissionSection").style.display = "unset";
|
|
||||||
|
|
||||||
showSubmitTimesIfNecessary();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
|
||||||
|
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||||
|
|
||||||
|
updateStartTimeChosen();
|
||||||
|
|
||||||
|
//display video times on screen
|
||||||
|
displaySponsorTimes();
|
||||||
|
|
||||||
|
//show submission section
|
||||||
|
document.getElementById("submissionSection").style.display = "unset";
|
||||||
|
|
||||||
|
showSubmitTimesIfNecessary();
|
||||||
|
}
|
||||||
|
|
||||||
//display the video times from the array
|
//display the video times from the array
|
||||||
function displaySponsorTimes() {
|
function displaySponsorTimes() {
|
||||||
//set it to the message
|
//set it to the message
|
||||||
document.getElementById("sponsorMessageTimes").innerHTML = getSponsorTimesMessage(sponsorTimes);
|
let sponsorMessageTimes = document.getElementById("sponsorMessageTimes");
|
||||||
|
|
||||||
|
//remove all children
|
||||||
|
while (sponsorMessageTimes.firstChild) {
|
||||||
|
sponsorMessageTimes.removeChild(sponsorMessageTimes.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
//add sponsor times
|
||||||
|
sponsorMessageTimes.appendChild(getSponsorTimesMessageDiv(sponsorTimes));
|
||||||
}
|
}
|
||||||
|
|
||||||
//display the video times from the array at the top, in a different section
|
//display the video times from the array at the top, in a different section
|
||||||
@@ -286,6 +365,196 @@ function getSponsorTimesMessage(sponsorTimes) {
|
|||||||
return sponsorTimesMessage;
|
return sponsorTimesMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the message that visually displays the video times
|
||||||
|
//this version is a div that contains each with delete buttons
|
||||||
|
function getSponsorTimesMessageDiv(sponsorTimes) {
|
||||||
|
// let sponsorTimesMessage = "";
|
||||||
|
let sponsorTimesContainer = document.createElement("div");
|
||||||
|
sponsorTimesContainer.id = "sponsorTimesContainer";
|
||||||
|
|
||||||
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
|
let currentSponsorTimeContainer = document.createElement("div");
|
||||||
|
currentSponsorTimeContainer.id = "sponsorTimeContainer" + i;
|
||||||
|
currentSponsorTimeContainer.className = "sponsorTime";
|
||||||
|
let currentSponsorTimeMessage = "";
|
||||||
|
|
||||||
|
let deleteButton = document.createElement("span");
|
||||||
|
deleteButton.id = "sponsorTimeDeleteButton" + i;
|
||||||
|
deleteButton.innerText = "Delete";
|
||||||
|
deleteButton.className = "mediumLink";
|
||||||
|
let index = i;
|
||||||
|
deleteButton.addEventListener("click", () => deleteSponsorTime(index));
|
||||||
|
|
||||||
|
let spacer = document.createElement("span");
|
||||||
|
spacer.innerText = " ";
|
||||||
|
|
||||||
|
let editButton = document.createElement("span");
|
||||||
|
editButton.id = "sponsorTimeEditButton" + i;
|
||||||
|
editButton.innerText = "Edit";
|
||||||
|
editButton.className = "mediumLink";
|
||||||
|
editButton.addEventListener("click", () => editSponsorTime(index));
|
||||||
|
|
||||||
|
for (let s = 0; s < sponsorTimes[i].length; s++) {
|
||||||
|
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
|
||||||
|
//if this is an end time
|
||||||
|
if (s == 1) {
|
||||||
|
timeMessage = " to " + timeMessage;
|
||||||
|
} else if (i > 0) {
|
||||||
|
//add commas if necessary
|
||||||
|
timeMessage = timeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSponsorTimeMessage += timeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
|
||||||
|
currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
|
||||||
|
|
||||||
|
sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
|
||||||
|
sponsorTimesContainer.appendChild(deleteButton);
|
||||||
|
|
||||||
|
//only if it is a complete sponsor time
|
||||||
|
if (sponsorTimes[i].length > 1) {
|
||||||
|
sponsorTimesContainer.appendChild(editButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sponsorTimesContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function editSponsorTime(index) {
|
||||||
|
if (document.getElementById("startTimeMinutes" + index) != null) {
|
||||||
|
//already open
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
|
||||||
|
|
||||||
|
//get sponsor time minutes and seconds boxes
|
||||||
|
let startTimeMinutes = document.createElement("input");
|
||||||
|
startTimeMinutes.id = "startTimeMinutes" + index;
|
||||||
|
startTimeMinutes.className = "sponsorTime";
|
||||||
|
startTimeMinutes.type = "text";
|
||||||
|
startTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][0]);
|
||||||
|
startTimeMinutes.style.width = "45";
|
||||||
|
|
||||||
|
let startTimeSeconds = document.createElement("input");
|
||||||
|
startTimeSeconds.id = "startTimeSeconds" + index;
|
||||||
|
startTimeSeconds.className = "sponsorTime";
|
||||||
|
startTimeSeconds.type = "text";
|
||||||
|
startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]);
|
||||||
|
startTimeSeconds.style.width = "60";
|
||||||
|
|
||||||
|
let endTimeMinutes = document.createElement("input");
|
||||||
|
endTimeMinutes.id = "endTimeMinutes" + index;
|
||||||
|
endTimeMinutes.className = "sponsorTime";
|
||||||
|
endTimeMinutes.type = "text";
|
||||||
|
endTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][1]);
|
||||||
|
endTimeMinutes.style.width = "45";
|
||||||
|
|
||||||
|
let endTimeSeconds = document.createElement("input");
|
||||||
|
endTimeSeconds.id = "endTimeSeconds" + index;
|
||||||
|
endTimeSeconds.className = "sponsorTime";
|
||||||
|
endTimeSeconds.type = "text";
|
||||||
|
endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]);
|
||||||
|
endTimeSeconds.style.width = "60";
|
||||||
|
|
||||||
|
let colonText = document.createElement("span");
|
||||||
|
colonText.innerText = ":";
|
||||||
|
|
||||||
|
let toText = document.createElement("span");
|
||||||
|
toText.innerText = " to ";
|
||||||
|
|
||||||
|
//remove all children to replace
|
||||||
|
while (sponsorTimeContainer.firstChild) {
|
||||||
|
sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
sponsorTimeContainer.appendChild(startTimeMinutes);
|
||||||
|
sponsorTimeContainer.appendChild(colonText);
|
||||||
|
sponsorTimeContainer.appendChild(startTimeSeconds);
|
||||||
|
sponsorTimeContainer.appendChild(toText);
|
||||||
|
sponsorTimeContainer.appendChild(endTimeMinutes);
|
||||||
|
sponsorTimeContainer.appendChild(colonText);
|
||||||
|
sponsorTimeContainer.appendChild(endTimeSeconds);
|
||||||
|
|
||||||
|
//add save button and remove edit button
|
||||||
|
let saveButton = document.createElement("span");
|
||||||
|
saveButton.id = "sponsorTimeSaveButton" + index;
|
||||||
|
saveButton.innerText = "Save";
|
||||||
|
saveButton.className = "mediumLink";
|
||||||
|
saveButton.addEventListener("click", () => saveSponsorTimeEdit(index));
|
||||||
|
|
||||||
|
let editButton = document.getElementById("sponsorTimeEditButton" + index);
|
||||||
|
let sponsorTimesContainer = document.getElementById("sponsorTimesContainer");
|
||||||
|
|
||||||
|
sponsorTimesContainer.removeChild(editButton);
|
||||||
|
sponsorTimesContainer.appendChild(saveButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSponsorTimeEdit(index) {
|
||||||
|
let startTimeMinutes = document.getElementById("startTimeMinutes" + index);
|
||||||
|
let startTimeSeconds = document.getElementById("startTimeSeconds" + index);
|
||||||
|
|
||||||
|
let endTimeMinutes = document.getElementById("endTimeMinutes" + index);
|
||||||
|
let endTimeSeconds = document.getElementById("endTimeSeconds" + index);
|
||||||
|
|
||||||
|
sponsorTimes[index][0] = parseInt(startTimeMinutes.value) * 60 + parseFloat(startTimeSeconds.value);
|
||||||
|
sponsorTimes[index][1] = parseInt(endTimeMinutes.value) * 60 + parseFloat(endTimeSeconds.value);
|
||||||
|
|
||||||
|
//save this
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||||
|
|
||||||
|
displaySponsorTimes();
|
||||||
|
}
|
||||||
|
|
||||||
|
//deletes the sponsor time submitted at an index
|
||||||
|
function deleteSponsorTime(index) {
|
||||||
|
//if it is not a complete sponsor time
|
||||||
|
if (sponsorTimes[index].length < 2) {
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeStartSponsorButton",
|
||||||
|
showStartSponsor: true,
|
||||||
|
uploadButtonVisible: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
resetStartTimeChosen();
|
||||||
|
}
|
||||||
|
|
||||||
|
sponsorTimes.splice(index, 1);
|
||||||
|
|
||||||
|
//save this
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||||
|
|
||||||
|
//update display
|
||||||
|
displaySponsorTimes();
|
||||||
|
|
||||||
|
//if they are all removed
|
||||||
|
if (sponsorTimes.length == 0) {
|
||||||
|
//update chrome tab
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeStartSponsorButton",
|
||||||
|
showStartSponsor: true,
|
||||||
|
uploadButtonVisible: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//hide submission section
|
||||||
|
document.getElementById("submissionSection").style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearTimes() {
|
function clearTimes() {
|
||||||
//send new sponsor time state to tab
|
//send new sponsor time state to tab
|
||||||
if (sponsorTimes.length > 0) {
|
if (sponsorTimes.length > 0) {
|
||||||
@@ -340,8 +609,11 @@ function submitTimes() {
|
|||||||
} else if(response.statusCode == 409) {
|
} else if(response.statusCode == 409) {
|
||||||
document.getElementById("submitTimesInfoMessage").innerText = "This has already been submitted before";
|
document.getElementById("submitTimesInfoMessage").innerText = "This has already been submitted before";
|
||||||
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
||||||
|
} else if(response.statusCode == 502) {
|
||||||
|
document.getElementById("submitTimesInfoMessage").innerText = "It seems the server is down. Contact the dev to inform them. Error code " + response.statusCode;
|
||||||
|
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("submitTimesInfoMessage").innerText = "There was an error submitting your sponsor times, please try again later";
|
document.getElementById("submitTimesInfoMessage").innerText = "There was an error submitting your sponsor times, please try again later. Error code " + response.statusCode;
|
||||||
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,7 +633,7 @@ function showNoticeAgain() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("showNoticeAgain").style.display = "none";
|
SB.showNoticeAgain.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideVideoPlayerControls() {
|
function hideVideoPlayerControls() {
|
||||||
@@ -377,8 +649,8 @@ function hideVideoPlayerControls() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "none";
|
SB.hideVideoPlayerControls.style.display = "none";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "unset";
|
SB.showVideoPlayerControls.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVideoPlayerControls() {
|
function showVideoPlayerControls() {
|
||||||
@@ -394,15 +666,117 @@ function showVideoPlayerControls() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "unset";
|
SB.hideVideoPlayerControls.style.display = "unset";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "none";
|
SB.showVideoPlayerControls.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideInfoButtonPlayerControls() {
|
||||||
|
chrome.storage.sync.set({"hideInfoButtonPlayerControls": true});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeInfoButtonPlayerControlsVisibility",
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.hideInfoButtonPlayerControls.style.display = "none";
|
||||||
|
SB.showInfoButtonPlayerControls.style.display = "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInfoButtonPlayerControls() {
|
||||||
|
chrome.storage.sync.set({"hideInfoButtonPlayerControls": false});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeVideoPlayerCochangeInfoButtonPlayerControlsVisibilityntrolsVisibility",
|
||||||
|
value: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.hideInfoButtonPlayerControls.style.display = "unset";
|
||||||
|
SB.showInfoButtonPlayerControls.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideDeleteButtonPlayerControls() {
|
||||||
|
chrome.storage.sync.set({"hideDeleteButtonPlayerControls": true});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeDeleteButtonPlayerControlsVisibility",
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.hideDeleteButtonPlayerControls.style.display = "none";
|
||||||
|
SB.showDeleteButtonPlayerControls.style.display = "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
function showDeleteButtonPlayerControls() {
|
||||||
|
chrome.storage.sync.set({"hideDeleteButtonPlayerControls": false});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "changeVideoPlayerCochangeDeleteButtonPlayerControlsVisibilityntrolsVisibility",
|
||||||
|
value: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.hideDeleteButtonPlayerControls.style.display = "unset";
|
||||||
|
SB.showDeleteButtonPlayerControls.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableSponsorViewTracking() {
|
||||||
|
chrome.storage.sync.set({"trackViewCount": false});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "trackViewCount",
|
||||||
|
value: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.disableSponsorViewTracking.style.display = "none";
|
||||||
|
SB.enableSponsorViewTracking.style.display = "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableSponsorViewTracking() {
|
||||||
|
chrome.storage.sync.set({"trackViewCount": true});
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, function(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
|
message: "trackViewCount",
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SB.enableSponsorViewTracking.style.display = "none";
|
||||||
|
SB.disableSponsorViewTracking.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStartTimeChosen() {
|
function updateStartTimeChosen() {
|
||||||
//update startTimeChosen variable
|
//update startTimeChosen variable
|
||||||
if (!startTimeChosen) {
|
if (!startTimeChosen) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
|
||||||
} else {
|
} else {
|
||||||
resetStartTimeChosen();
|
resetStartTimeChosen();
|
||||||
}
|
}
|
||||||
@@ -411,7 +785,7 @@ function updateStartTimeChosen() {
|
|||||||
//set it to false
|
//set it to false
|
||||||
function resetStartTimeChosen() {
|
function resetStartTimeChosen() {
|
||||||
startTimeChosen = false;
|
startTimeChosen = false;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Starts Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Starts Now";
|
||||||
}
|
}
|
||||||
|
|
||||||
//hides and shows the submit times button when needed
|
//hides and shows the submit times button when needed
|
||||||
@@ -440,7 +814,7 @@ function displayNoVideo() {
|
|||||||
|
|
||||||
function reportAnIssue() {
|
function reportAnIssue() {
|
||||||
document.getElementById("issueReporterContainer").style.display = "unset";
|
document.getElementById("issueReporterContainer").style.display = "unset";
|
||||||
document.getElementById("reportAnIssue").style.display = "none";
|
SB.reportAnIssue.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVoteMessage(message, UUID) {
|
function addVoteMessage(message, UUID) {
|
||||||
@@ -477,13 +851,23 @@ function vote(type, UUID) {
|
|||||||
//failure: duplicate vote
|
//failure: duplicate vote
|
||||||
addVoteMessage("You have already voted this way before.", UUID)
|
addVoteMessage("You have already voted this way before.", UUID)
|
||||||
} else if (response.successType == -1) {
|
} else if (response.successType == -1) {
|
||||||
//failure: duplicate vote
|
if (response.statusCode == 502) {
|
||||||
addVoteMessage("A connection error has occured.", UUID)
|
addVoteMessage("It seems the sever is down. Contact the dev immediately.", UUID)
|
||||||
|
} else {
|
||||||
|
//failure: unknown error
|
||||||
|
addVoteMessage("A connection error has occured. Error code: " + response.statusCode, UUID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hideDiscordButton() {
|
||||||
|
chrome.storage.sync.set({"hideDiscordLink": false});
|
||||||
|
|
||||||
|
SB.discordButtonContainer.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
//converts time in seconds to minutes:seconds
|
//converts time in seconds to minutes:seconds
|
||||||
function getFormattedTime(seconds) {
|
function getFormattedTime(seconds) {
|
||||||
let minutes = Math.floor(seconds / 60);
|
let minutes = Math.floor(seconds / 60);
|
||||||
@@ -498,6 +882,24 @@ function getFormattedTime(seconds) {
|
|||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//converts time in seconds to minutes
|
||||||
|
function getTimeInMinutes(seconds) {
|
||||||
|
let minutes = Math.floor(seconds / 60);
|
||||||
|
|
||||||
|
return minutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//converts time in seconds to seconds past the last minute
|
||||||
|
function getTimeInFormattedSeconds(seconds) {
|
||||||
|
let secondsFormatted = (seconds % 60).toFixed(3);
|
||||||
|
|
||||||
|
if (secondsFormatted < 10) {
|
||||||
|
secondsFormatted = "0" + secondsFormatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
return secondsFormatted;
|
||||||
|
}
|
||||||
|
|
||||||
function sendRequestToServer(type, address, callback) {
|
function sendRequestToServer(type, address, callback) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
@@ -521,4 +923,4 @@ function getYouTubeVideoID(url) { // Return video id or false
|
|||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
return (match && match[7].length == 11) ? match[7] : false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user