Skip to content

Commit

Permalink
Merge pull request #308 from ajayyy/experimental
Browse files Browse the repository at this point in the history
Skipping Fixes
  • Loading branch information
ajayyy committed Mar 31, 2020
2 parents f4a129b + 36d7931 commit 88350e3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -67,10 +67,12 @@ jobs:
uses: Shopify/upload-to-release@master
with:
args: builds/ChromeExtension.zip
name: ChromeExtension.zip
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to release
uses: Shopify/upload-to-release@master
with:
args: builds/FirefoxExtension.zip
name: FirefoxExtension.zip
repo-token: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion manifest/manifest.json
@@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.2.23",
"version": "1.2.24",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [{
Expand Down
4 changes: 0 additions & 4 deletions src/background.ts
Expand Up @@ -88,10 +88,6 @@ chrome.runtime.onInstalled.addListener(function (object) {
const newUserID = utils.generateUserID();
//save this UUID
Config.config.userID = newUserID;

//TODO: Remove when mobile support is old
// Don't show this to new users
// Config.config.mobileUpdateShowCount = 1;
}
}, 1500);
});
Expand Down
57 changes: 40 additions & 17 deletions src/content.ts
Expand Up @@ -21,7 +21,7 @@ var UUIDs = [];
var sponsorVideoID = null;

// Skips are scheduled to ensure precision.
// Skips are rescheduled every seeked event.
// Skips are rescheduled every seeking event.
// Skips are canceled every seeking event
var currentSkipSchedule: NodeJS.Timeout = null;
var seekListenerSetUp = false
Expand All @@ -35,6 +35,9 @@ var sponsorSkipped = [];
//the video
var video: HTMLVideoElement;

/** The last time this video was seeking to */
var lastVideoTime: number = null;

var onInvidious;
var onMobileYouTube;

Expand Down Expand Up @@ -476,12 +479,24 @@ function startSponsorSchedule(currentTime?: number): void {
let forcedSkipTime: number = null;

if (video.currentTime >= skipTime[0] && video.currentTime < skipTime[1]) {
skipToTime(video, skipInfo.index, skipInfo.array, skipInfo.openNotice);

if (Config.config.disableAutoSkip) {
forcedSkipTime = skipTime[0] + 0.001;
// Double check that the videoID is correct
// TODO: Remove this bug catching if statement when the bug is found
let currentVideoID = getYouTubeVideoID(document.URL);
if (currentVideoID == sponsorVideoID) {
skipToTime(video, skipInfo.index, skipInfo.array, skipInfo.openNotice);

if (Config.config.disableAutoSkip) {
forcedSkipTime = skipTime[0] + 0.001;
} else {
forcedSkipTime = skipTime[1];
}
} else {
forcedSkipTime = skipTime[1];
// Something has really gone wrong
console.error("[SponsorBlock] The videoID recorded when trying to skip is different than what it should be.");
console.error("[SponsorBlock] VideoID recorded: " + sponsorVideoID + ". Actual VideoID: " + currentVideoID);

// Video ID change occured
videoIDChange(currentVideoID);
}
}

Expand Down Expand Up @@ -533,12 +548,27 @@ function sponsorsLookup(id: string, channelIDPromise?) {
startSponsorSchedule();
}
});
video.addEventListener('seeked', () => {
if (!video.paused) startSponsorSchedule();
video.addEventListener('seeking', () => {
// Reset lastCheckVideoTime
lastCheckVideoTime = -1
lastCheckTime = 0;

lastVideoTime = video.currentTime;

if (!video.paused){
startSponsorSchedule();
}
});
video.addEventListener('ratechange', () => startSponsorSchedule());
video.addEventListener('seeking', cancelSponsorSchedule);
video.addEventListener('pause', cancelSponsorSchedule);
video.addEventListener('pause', () => {
// Reset lastCheckVideoTime
lastCheckVideoTime = -1;
lastCheckTime = 0;

lastVideoTime = video.currentTime;

cancelSponsorSchedule();
});

startSponsorSchedule();
}
Expand Down Expand Up @@ -872,13 +902,6 @@ function skipToTime(v, index, sponsorTimes, openNotice) {

let skipNotice = new SkipNotice(this, currentUUID, Config.config.disableAutoSkip, skipNoticeContentContainer);

//TODO: Remove this when Mobile support is old
if (Config.config.mobileUpdateShowCount < 1) {
skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("mobileUpdateInfo"));

Config.config.mobileUpdateShowCount += 1;
}

//auto-upvote this sponsor
if (Config.config.trackViewCount && !Config.config.disableAutoSkip && Config.config.autoUpvote) {
vote(1, currentUUID, null);
Expand Down

0 comments on commit 88350e3

Please sign in to comment.