mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 07:57:09 +03:00
Merge pull request #4 from ajayyy/experimental
View count additions and fixes
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
content-config.js
|
config.js
|
||||||
ignored
|
ignored
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
//this file is loaded along iwth content.js
|
|
||||||
//this file sets the server to connect to, and is gitignored
|
|
||||||
var serverAddress = "http://localhost";
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
.playerButton {
|
.playerButtonImage {
|
||||||
height: 60%;
|
height: 60%;
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@@ -6,6 +6,10 @@
|
|||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.playerButton {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
.sponsorSkipObject {
|
.sponsorSkipObject {
|
||||||
font-family: 'Source Sans Pro', sans-serif;
|
font-family: 'Source Sans Pro', sans-serif;
|
||||||
}
|
}
|
||||||
|
|||||||
52
content.js
52
content.js
@@ -21,6 +21,9 @@ 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;
|
||||||
|
|
||||||
|
//the last time skipped to
|
||||||
|
var lastTimeSkippedTo = -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
|
||||||
var lastSponsorTimeSkipped = null;
|
var lastSponsorTimeSkipped = null;
|
||||||
@@ -117,7 +120,6 @@ function videoIDChange(id) {
|
|||||||
|
|
||||||
function sponsorsLookup(id) {
|
function sponsorsLookup(id) {
|
||||||
v = document.querySelector('video') // Youtube video player
|
v = document.querySelector('video') // Youtube video player
|
||||||
let xmlhttp = new XMLHttpRequest();
|
|
||||||
|
|
||||||
//check database for sponsor times
|
//check database for sponsor times
|
||||||
sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
|
sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
|
||||||
@@ -151,28 +153,34 @@ 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
|
//the sponsor time is in between these times, skip it
|
||||||
//if the time difference is more than 1 second, than the there was probably a skip in time,
|
//if the time difference is more than 1 second, than the there was probably a skip in time,
|
||||||
// and it's not due to playback
|
// and it's not due to playback
|
||||||
if (Math.abs(v.currentTime - lastTime) < 1 && sponsorTimes[i][0] >= lastTime && sponsorTimes[i][0] <= v.currentTime) {
|
//also check if the last time skipped to is not too close to now, to make sure not to get too many
|
||||||
//skip it
|
// sponsor times in a row (from one troll)
|
||||||
v.currentTime = sponsorTimes[i][1];
|
if (Math.abs(v.currentTime - lastTime) < 1 && sponsorTimes[i][0] >= lastTime && sponsorTimes[i][0] <= v.currentTime &&
|
||||||
|
(lastTimeSkippedTo == -1 || Math.abs(v.currentTime - lastTimeSkippedTo) > 1)) {
|
||||||
|
//skip it
|
||||||
|
v.currentTime = sponsorTimes[i][1];
|
||||||
|
lastTimeSkippedTo = sponsorTimes[i][1];
|
||||||
|
|
||||||
lastSponsorTimeSkipped = sponsorTimes[i][0];
|
lastSponsorTimeSkipped = sponsorTimes[i][0];
|
||||||
|
|
||||||
let currentUUID = UUIDs[i];
|
let currentUUID = UUIDs[i];
|
||||||
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();
|
||||||
|
|
||||||
setTimeout(() => closeSkipNotice(currentUUID), 7000);
|
setTimeout(() => closeSkipNotice(currentUUID), 7000);
|
||||||
}
|
|
||||||
|
|
||||||
lastTime = v.currentTime;
|
//send telemetry that a this sponsor was skipped happened
|
||||||
|
sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
lastTime = v.currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function goBackToPreviousTime(UUID) {
|
function goBackToPreviousTime(UUID) {
|
||||||
@@ -193,13 +201,13 @@ function addPlayerControlsButton() {
|
|||||||
|
|
||||||
let startSponsorButton = document.createElement("button");
|
let startSponsorButton = document.createElement("button");
|
||||||
startSponsorButton.id = "startSponsorButton";
|
startSponsorButton.id = "startSponsorButton";
|
||||||
startSponsorButton.className = "ytp-button";
|
startSponsorButton.className = "ytp-button playerButton";
|
||||||
startSponsorButton.setAttribute("title", "Sponsor Starts Now");
|
startSponsorButton.setAttribute("title", "Sponsor Starts Now");
|
||||||
startSponsorButton.addEventListener("click", startSponsorClicked);
|
startSponsorButton.addEventListener("click", startSponsorClicked);
|
||||||
|
|
||||||
let startSponsorImage = document.createElement("img");
|
let startSponsorImage = document.createElement("img");
|
||||||
startSponsorImage.id = "startSponsorImage";
|
startSponsorImage.id = "startSponsorImage";
|
||||||
startSponsorImage.className = "playerButton";
|
startSponsorImage.className = "playerButtonImage";
|
||||||
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
//add the image to the button
|
//add the image to the button
|
||||||
@@ -269,7 +277,7 @@ function addSubmitButton() {
|
|||||||
//make a submit button
|
//make a submit button
|
||||||
let submitButton = document.createElement("button");
|
let submitButton = document.createElement("button");
|
||||||
submitButton.id = "submitButton";
|
submitButton.id = "submitButton";
|
||||||
submitButton.className = "ytp-button";
|
submitButton.className = "ytp-button playerButton";
|
||||||
submitButton.setAttribute("title", "Submit Sponsor Times");
|
submitButton.setAttribute("title", "Submit Sponsor Times");
|
||||||
submitButton.addEventListener("click", submitSponsorTimes);
|
submitButton.addEventListener("click", submitSponsorTimes);
|
||||||
//hide it at the start
|
//hide it at the start
|
||||||
@@ -277,7 +285,7 @@ function addSubmitButton() {
|
|||||||
|
|
||||||
let submitImage = document.createElement("img");
|
let submitImage = document.createElement("img");
|
||||||
submitImage.id = "submitButtonImage";
|
submitImage.id = "submitButtonImage";
|
||||||
submitImage.className = "playerButton";
|
submitImage.className = "playerButtonImage";
|
||||||
submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
//add the image to the button
|
//add the image to the button
|
||||||
|
|||||||
61
firefox_manifest.json
Normal file
61
firefox_manifest.json
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"name": "SponsorBlock - YouTube Sponsorship Blocker",
|
||||||
|
"short_name": "SponsorBlock",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"https://*.youtube.com/*"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"config.js",
|
||||||
|
"content.js"
|
||||||
|
],
|
||||||
|
"css": [
|
||||||
|
"content.css",
|
||||||
|
"./libs/Source+Sans+Pro.css"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"web_accessible_resources": [
|
||||||
|
"icons/LogoSponsorBlocker256px.png",
|
||||||
|
"icons/IconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerStartIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerStopIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
||||||
|
"icons/upvote.png",
|
||||||
|
"icons/downvote.png"
|
||||||
|
],
|
||||||
|
"permissions": [
|
||||||
|
"tabs",
|
||||||
|
"storage",
|
||||||
|
"notifications",
|
||||||
|
"https://sponsor.ajay.app/*"
|
||||||
|
],
|
||||||
|
"browser_action": {
|
||||||
|
"default_title": "SponsorBlock",
|
||||||
|
"default_popup": "popup.html"
|
||||||
|
},
|
||||||
|
"background": {
|
||||||
|
"scripts":[
|
||||||
|
"config.js",
|
||||||
|
"background.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"16": "icons/IconSponsorBlocker16px.png",
|
||||||
|
"32": "icons/IconSponsorBlocker32px.png",
|
||||||
|
"64": "icons/LogoSponsorBlocker64px.png",
|
||||||
|
"128": "icons/LogoSponsorBlocker128px.png",
|
||||||
|
"256": "icons/LogoSponsorBlocker256px.png"
|
||||||
|
},
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "sponsorBlocker@ajay.app",
|
||||||
|
"strict_min_version": "57.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manifest_version": 2
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 9.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "YTSponsorSkip",
|
"name": "SponsorBlock - YouTube Sponsorship Blocker",
|
||||||
"version": "1.0",
|
"short_name": "SponsorBlock",
|
||||||
"description": "Skip youtube video sponsors.",
|
"version": "1.0.1",
|
||||||
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
@@ -30,7 +31,8 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage",
|
"storage",
|
||||||
"notifications"
|
"notifications",
|
||||||
|
"https://sponsor.ajay.app/*"
|
||||||
],
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_title": "SponsorBlock",
|
"default_title": "SponsorBlock",
|
||||||
|
|||||||
25
popup.html
25
popup.html
@@ -41,8 +41,26 @@
|
|||||||
|
|
||||||
<h2 class="recordingSubtitle">Record the times of a sponsorship</h2>
|
<h2 class="recordingSubtitle">Record the times of a sponsorship</h2>
|
||||||
|
|
||||||
<p id="sponsorTimesContributionsDisplay" style="display: none">
|
<p>
|
||||||
So far, you've submitted no sponsor times.
|
<span id=sponsorTimesContributionsContainer style="display: none">
|
||||||
|
So far, you've submitted
|
||||||
|
<span id="sponsorTimesContributionsDisplay">
|
||||||
|
0
|
||||||
|
</span>
|
||||||
|
<span id="sponsorTimesContributionsDisplayEndWord">
|
||||||
|
sponsors.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span id=sponsorTimesViewsContainer style="display: none">
|
||||||
|
You have saved people from
|
||||||
|
<span id="sponsorTimesViewsDisplay">
|
||||||
|
0
|
||||||
|
</span>
|
||||||
|
<span id="sponsorTimesViewsDisplayEndWord">
|
||||||
|
sponsor segments.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@@ -103,5 +121,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
<!-- Scripts that need to load after the html -->
|
||||||
|
<script src="config.js"></script>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</html>
|
</html>
|
||||||
57
popup.js
57
popup.js
@@ -41,17 +41,49 @@ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
|||||||
//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 sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
|
||||||
|
let sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
|
||||||
|
|
||||||
if (result.sponsorTimesContributed > 1) {
|
if (result.sponsorTimesContributed > 1) {
|
||||||
sponsorTimesContributionsDisplay.innerText = "So far, you've submitted " + result.sponsorTimesContributed + " sponsor times.";
|
sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
|
||||||
} else {
|
} else {
|
||||||
sponsorTimesContributionsDisplay.innerText = "So far, you've submitted " + result.sponsorTimesContributed + " sponsor time.";
|
sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
|
||||||
}
|
}
|
||||||
sponsorTimesContributionsDisplay.style.display = "unset";
|
sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
||||||
|
sponsorTimesContributionsContainer.style.display = "unset";
|
||||||
|
|
||||||
|
//get the userID
|
||||||
|
chrome.storage.sync.get(["userID"], function(result) {
|
||||||
|
let userID = result.userID;
|
||||||
|
if (userID != undefined) {
|
||||||
|
//there are probably some views on these submissions then
|
||||||
|
//get the amount of views from the sponsors submitted
|
||||||
|
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
||||||
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
|
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
||||||
|
|
||||||
|
if (viewCount != 0) {
|
||||||
|
let sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsContainer");
|
||||||
|
let sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplay");
|
||||||
|
let sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayEndWord");
|
||||||
|
|
||||||
|
if (viewCount > 1) {
|
||||||
|
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
|
||||||
|
} else {
|
||||||
|
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
|
||||||
|
}
|
||||||
|
sponsorTimesViewsDisplay.innerText = viewCount;
|
||||||
|
sponsorTimesViewsContainer.style.display = "unset";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
@@ -466,6 +498,25 @@ function getFormattedTime(seconds) {
|
|||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendRequestToServer(type, address, callback) {
|
||||||
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xmlhttp.open(type, serverAddress + address, true);
|
||||||
|
|
||||||
|
if (callback != undefined) {
|
||||||
|
xmlhttp.onreadystatechange = function () {
|
||||||
|
callback(xmlhttp, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
xmlhttp.onerror = function(ev) {
|
||||||
|
callback(xmlhttp, true);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//submit this request
|
||||||
|
xmlhttp.send();
|
||||||
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Return video id or false
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user