Skip to content

Commit

Permalink
add support for full-video labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mchangrh committed Jul 1, 2022
1 parent 68cc648 commit 00f1012
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 22 deletions.
4 changes: 3 additions & 1 deletion docs/sb-loader.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const categories = [
"outro",
"preview",
"music_offtopic",
"exclusive_access"
]
const actionTypes = [
"skip",
"mute"
"mute",
"full"
]
const skipThreshold = [0.2, 1] // skip from between time-[0] and time+[1]
const serverEndpoint = "https://sponsor.ajay.app"
Expand Down
2 changes: 1 addition & 1 deletion docs/sb-nosettings.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/sb.bookmarklet.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 39 additions & 5 deletions docs/sb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const categories = [
"outro",
"preview",
"music_offtopic",
"exclusive_access"
]
const actionTypes = [
"skip",
"mute"
"mute",
"full"
]
const skipThreshold = [0.2, 1] // skip from between time-[0] and time+[1]
const serverEndpoint = "https://sponsor.ajay.app"
Expand All @@ -26,10 +28,10 @@ https://github.com/mchangrh/sb.js
Uses SponsorBlock data licensed used under CC BY-NC-SA 4.0 from https://sponsor.ajay.app/
LICENCED UNDER LGPL-3.0-or-later */
const VERSION = "1.0.1"; // version constant
const VERSION = "1.1.0"; // version constant

// initial setup
let video, videoID, skipSegments, muteSegments, muteEndTime;
let video, videoID, skipSegments, muteSegments, muteEndTime, videoLabel;

// functions
const getVideoID = () => new URL(window.location.href).searchParams.get("v");
Expand Down Expand Up @@ -64,6 +66,9 @@ function fetch(videoID) {
.filter((segment) => segment.actionType === "mute")
.map((s) => [s.segment[0], { end: s.segment[1], uuid: s.UUID }])
);
// create full video label
videoLabel = data.filter((s) => s.actionType === "full")
createVideoLabel(videoLabel)
});
console.log("[SB.js] Loaded Segments");
}
Expand Down Expand Up @@ -114,10 +119,39 @@ function findEndTime(now, map) {
return endTime;
}

function createVideoLabel (videoLabel) {
if (!videoLabel.length) return;
// await title
const title = document.querySelector("#title h1, h1.title.ytd-video-primary-info-renderer");
if (!title) {
setTimeout(createVideoLabel, 200, videoLabel);
return
}
title.style = "display: flex;";
const category = videoLabel[0].category
const bgMap = {
sponsor: "#0d0",
selfpromo: "#ff0",
exclusive_access: "#085"
}
const fgMap = {
selfpromo: "#111",
sponsor: "#fff",
exclusive_access: "#fff"
}
const label = document.createElement("span");
label.innerText = label
label.id = "sbjs-videolabel";
label.style = `color: ${fgMap[category]}; background-color: ${bgMap[category]}; display: flex; margin: 0 5px;`;
// prepend to title
title.prepend(label);
}

const reset = () => {
video = null;
videoID = null;
video = undefined;
videoID = undefined;
muteEndTime = 0;
videoLabel = undefined;
skipSegments = [];
muteSegments = [];
};
Expand Down
2 changes: 1 addition & 1 deletion docs/sb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 39 additions & 5 deletions docs/sb.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const categories = [
"outro",
"preview",
"music_offtopic",
"exclusive_access"
]
const actionTypes = [
"skip",
"mute"
"mute",
"full"
]
const skipThreshold = [0.2, 1] // skip from between time-[0] and time+[1]
const serverEndpoint = "https://sponsor.ajay.app"
Expand All @@ -36,10 +38,10 @@ https://github.com/mchangrh/sb.js
Uses SponsorBlock data licensed used under CC BY-NC-SA 4.0 from https://sponsor.ajay.app/
LICENCED UNDER LGPL-3.0-or-later */
const VERSION = "1.0.1"; // version constant
const VERSION = "1.1.0"; // version constant

// initial setup
let video, videoID, skipSegments, muteSegments, muteEndTime;
let video, videoID, skipSegments, muteSegments, muteEndTime, videoLabel;

// functions
const getVideoID = () => new URL(window.location.href).searchParams.get("v");
Expand Down Expand Up @@ -74,6 +76,9 @@ function fetch(videoID) {
.filter((segment) => segment.actionType === "mute")
.map((s) => [s.segment[0], { end: s.segment[1], uuid: s.UUID }])
);
// create full video label
videoLabel = data.filter((s) => s.actionType === "full")
createVideoLabel(videoLabel)
});
console.log("[SB.js] Loaded Segments");
}
Expand Down Expand Up @@ -124,10 +129,39 @@ function findEndTime(now, map) {
return endTime;
}

function createVideoLabel (videoLabel) {
if (!videoLabel.length) return;
// await title
const title = document.querySelector("#title h1, h1.title.ytd-video-primary-info-renderer");
if (!title) {
setTimeout(createVideoLabel, 200, videoLabel);
return
}
title.style = "display: flex;";
const category = videoLabel[0].category
const bgMap = {
sponsor: "#0d0",
selfpromo: "#ff0",
exclusive_access: "#085"
}
const fgMap = {
selfpromo: "#111",
sponsor: "#fff",
exclusive_access: "#fff"
}
const label = document.createElement("span");
label.innerText = label
label.id = "sbjs-videolabel";
label.style = `color: ${fgMap[category]}; background-color: ${bgMap[category]}; display: flex; margin: 0 5px;`;
// prepend to title
title.prepend(label);
}

const reset = () => {
video = null;
videoID = null;
video = undefined;
videoID = undefined;
muteEndTime = 0;
videoLabel = undefined;
skipSegments = [];
muteSegments = [];
};
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mchangrh/sb.js",
"version": "1.0.1",
"version": "1.1.0",
"description": "SponsorBlock userscript/bookmarklet clients",
"main": "docs/sb.min.js",
"scripts": {
Expand Down
Loading

0 comments on commit 00f1012

Please sign in to comment.