Merge pull request #356 from ajayyy/react

Fix preview sponsors not skipping
This commit is contained in:
Ajay Ramachandran
2020-05-17 00:00:08 -04:00
committed by GitHub
6 changed files with 55 additions and 38 deletions

View File

@@ -18,9 +18,6 @@ jobs:
- name: Copy configuration - name: Copy configuration
run: cp config.json.example config.json run: cp config.json.example config.json
- name: Install Zip
run: sudo apt-get install zip
# Create Chrome artifacts # Create Chrome artifacts
- name: Create Chrome artifacts - name: Create Chrome artifacts
run: npm run build:chrome run: npm run build:chrome
@@ -30,9 +27,7 @@ jobs:
path: dist path: dist
- run: mkdir ./builds - run: mkdir ./builds
- name: Zip Artifacts - name: Zip Artifacts
run: cd ./dist run: cd ./dist ; zip -r ../builds/ChromeExtension.zip *
- run: zip -r ../builds/ChromeExtension.zip *
- run: cd ../
# Create Firefox artifacts # Create Firefox artifacts
- name: Create Firefox artifacts - name: Create Firefox artifacts
@@ -42,11 +37,7 @@ jobs:
name: FirefoxExtension name: FirefoxExtension
path: dist path: dist
- name: Zip Artifacts - name: Zip Artifacts
run: cd ./dist run: cd ./dist ; zip -r ../builds/FirefoxExtension.zip *
- uses: montudor/action-zip@v0.1.0
with:
args: zip -r ../builds/FirefoxExtension.zip *
- run: cd ../
# Create Beta artifacts (Builds with the name changed to beta) # Create Beta artifacts (Builds with the name changed to beta)
- name: Create Chrome Beta artifacts - name: Create Chrome Beta artifacts
@@ -56,9 +47,7 @@ jobs:
name: ChromeExtensionBeta name: ChromeExtensionBeta
path: dist path: dist
- name: Zip Artifacts - name: Zip Artifacts
run: cd ./dist run: cd ./dist ; zip -r ../builds/ChromeExtensionBeta.zip *
- run: zip -r ../builds/ChromeExtensionBeta.zip *
- run: cd ../
- name: Create Firefox Beta artifacts - name: Create Firefox Beta artifacts
run: npm run build:firefox -- --env.stream=beta run: npm run build:firefox -- --env.stream=beta
@@ -67,9 +56,7 @@ jobs:
name: FirefoxExtensionBeta name: FirefoxExtensionBeta
path: dist path: dist
- name: Zip Artifacts - name: Zip Artifacts
run: cd ./dist run: cd ./dist ; zip -r ../builds/FirefoxExtensionBeta.zip *
- run: zip -r ../builds/FirefoxExtensionBeta.zip *
- run: cd ../
# Create Firefox Signed Beta version # Create Firefox Signed Beta version
- name: Create Firefox Signed Beta artifacts - name: Create Firefox Signed Beta artifacts
@@ -80,9 +67,7 @@ jobs:
- name: Install rename - name: Install rename
run: sudo apt-get install rename run: sudo apt-get install rename
- name: Install signed file - name: Install signed file
run: cd ./web-ext-artifacts run: cd ./web-ext-artifacts ; rename 's/.*/FirefoxSignedInstaller.xpi/' *
- run: rename 's/.*/FirefoxSignedInstaller.xpi/' *
- run: cd ..
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: FirefoxExtensionSigned.xpi name: FirefoxExtensionSigned.xpi

View File

@@ -1,7 +1,7 @@
{ {
"name": "__MSG_fullName__", "name": "__MSG_fullName__",
"short_name": "__MSG_Name__", "short_name": "__MSG_Name__",
"version": "1.2.28.3", "version": "1.2.28.4",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_Description__", "description": "__MSG_Description__",
"content_scripts": [{ "content_scripts": [{

View File

@@ -35,9 +35,6 @@
"Segments": { "Segments": {
"message": "sponsor segments" "message": "sponsor segments"
}, },
"noticeTitle": {
"message": "Sponsor Skipped"
},
"reportButtonTitle": { "reportButtonTitle": {
"message": "Report" "message": "Report"
}, },
@@ -71,6 +68,9 @@
"paused": { "paused": {
"message": "Paused" "message": "Paused"
}, },
"manualPaused": {
"message": "Timer Stopped"
},
"confirmMSG": { "confirmMSG": {
"message": "To edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner." "message": "To edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
}, },
@@ -272,12 +272,12 @@
"errorCode": { "errorCode": {
"message": "Error Code: " "message": "Error Code: "
}, },
"noticeTitleNotSkipped": {
"message": "Skip Sponsor?"
},
"skip": { "skip": {
"message": "Skip" "message": "Skip"
}, },
"skipped": {
"message": "Skipped"
},
"disableAutoSkip": { "disableAutoSkip": {
"message": "Disable Auto Skip" "message": "Disable Auto Skip"
}, },
@@ -559,7 +559,7 @@
"message": "Consider Enabling Force Channel Check Before Skipping Sponsors" "message": "Consider Enabling Force Channel Check Before Skipping Sponsors"
}, },
"downvoteDescription": { "downvoteDescription": {
"message": "Incorrect" "message": "Incorrect/Wrong Timing"
}, },
"incorrectCategory": { "incorrectCategory": {
"message": "Wrong Category" "message": "Wrong Category"

View File

@@ -23,6 +23,7 @@ export interface NoticeState {
countdownTime: number, countdownTime: number,
countdownText: string, countdownText: string,
countdownManuallyPaused: boolean,
} }
class NoticeComponent extends React.Component<NoticeProps, NoticeState> { class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
@@ -55,6 +56,7 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
//the countdown until this notice closes //the countdown until this notice closes
countdownTime: maxCountdownTime(), countdownTime: maxCountdownTime(),
countdownText: null, countdownText: null,
countdownManuallyPaused: false
} }
} }
@@ -71,8 +73,8 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
<table id={"sponsorSkipNotice" + this.idSuffix} <table id={"sponsorSkipNotice" + this.idSuffix}
className={"sponsorSkipObject sponsorSkipNotice" + (this.props.fadeIn ? " sponsorSkipNoticeFadeIn" : "")} className={"sponsorSkipObject sponsorSkipNotice" + (this.props.fadeIn ? " sponsorSkipNoticeFadeIn" : "")}
style={noticeStyle} style={noticeStyle}
onMouseEnter={this.pauseCountdown.bind(this)} onMouseEnter={() => this.timerMouseEnter()}
onMouseLeave={this.startCountdown.bind(this)}> onMouseLeave={() => this.timerMouseLeave()}>
<tbody> <tbody>
{/* First row */} {/* First row */}
@@ -99,6 +101,7 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
{/* Time left */} {/* Time left */}
{this.props.timed ? ( {this.props.timed ? (
<span id={"sponsorSkipNoticeTimeLeft" + this.idSuffix} <span id={"sponsorSkipNoticeTimeLeft" + this.idSuffix}
onClick={() => this.toggleManualPause()}
className="sponsorSkipObject sponsorSkipNoticeTimeLeft"> className="sponsorSkipObject sponsorSkipNoticeTimeLeft">
{this.state.countdownText || (this.state.countdownTime + "s")} {this.state.countdownText || (this.state.countdownTime + "s")}
@@ -121,6 +124,30 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
); );
} }
timerMouseEnter() {
if (this.state.countdownManuallyPaused) return;
this.pauseCountdown();
}
timerMouseLeave() {
if (this.state.countdownManuallyPaused) return;
this.startCountdown();
}
toggleManualPause() {
this.setState({
countdownManuallyPaused: !this.state.countdownManuallyPaused
}, () => {
if (this.state.countdownManuallyPaused) {
this.pauseCountdown();
} else {
this.startCountdown();
}
});
}
//called every second to lower the countdown before hiding the notice //called every second to lower the countdown before hiding the notice
countdown() { countdown() {
if (!this.props.timed) return; if (!this.props.timed) return;
@@ -159,7 +186,7 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
//reset countdown and inform the user //reset countdown and inform the user
this.setState({ this.setState({
countdownTime: this.state.maxCountdownTime(), countdownTime: this.state.maxCountdownTime(),
countdownText: chrome.i18n.getMessage("paused") countdownText: this.state.countdownManuallyPaused ? chrome.i18n.getMessage("manualPaused") : chrome.i18n.getMessage("paused")
}); });
//remove the fade out class if it exists //remove the fade out class if it exists

View File

@@ -62,10 +62,10 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
this.contentContainer = props.contentContainer; this.contentContainer = props.contentContainer;
this.audio = null; this.audio = null;
let noticeTitle = chrome.i18n.getMessage("noticeTitle"); let noticeTitle = chrome.i18n.getMessage("category_" + this.getSponsorTime().category) + " " + chrome.i18n.getMessage("skipped");
if (!this.autoSkip) { if (!this.autoSkip) {
noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped"); noticeTitle = chrome.i18n.getMessage("skip") + " " + chrome.i18n.getMessage("category_" + this.getSponsorTime().category) + "?";
} }
//add notice //add notice
@@ -103,6 +103,11 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
} }
} }
// Helper method
getSponsorTime() {
return utils.getSponsorTimeFromUUID(this.contentContainer().sponsorTimes, this.UUID);
}
componentDidMount() { componentDidMount() {
if (Config.config.audioNotificationOnSkip && this.audio) { if (Config.config.audioNotificationOnSkip && this.audio) {
this.audio.volume = this.contentContainer().v.volume * 0.1; this.audio.volume = this.contentContainer().v.volume * 0.1;
@@ -215,7 +220,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
{/* Category Selector */} {/* Category Selector */}
<select id={"sponsorTimeCategories" + this.idSuffix} <select id={"sponsorTimeCategories" + this.idSuffix}
className="sponsorTimeCategories" className="sponsorTimeCategories"
defaultValue={utils.getSponsorTimeFromUUID(this.props.contentContainer().sponsorTimes, this.props.UUID).category} defaultValue={this.getSponsorTime().category}
ref={this.categoryOptionRef} ref={this.categoryOptionRef}
onChange={this.categorySelectionChange.bind(this)}> onChange={this.categorySelectionChange.bind(this)}>
@@ -319,7 +324,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
chrome.runtime.sendMessage({"message": "openConfig"}); chrome.runtime.sendMessage({"message": "openConfig"});
// Reset option to original // Reset option to original
event.target.value = utils.getSponsorTimeFromUUID(this.props.contentContainer().sponsorTimes, this.props.UUID).category; event.target.value = this.getSponsorTime().category;
return; return;
} }
} }
@@ -340,7 +345,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
getUnskippedModeInfo(buttonText: string) { getUnskippedModeInfo(buttonText: string) {
let maxCountdownTime = function() { let maxCountdownTime = function() {
let sponsorTime = utils.getSponsorTimeFromUUID(this.contentContainer().sponsorTimes, this.UUID); let sponsorTime = this.getSponsorTime();
let duration = Math.round((sponsorTime.segment[1] - this.contentContainer().v.currentTime) * (1 / this.contentContainer().v.playbackRate)); let duration = Math.round((sponsorTime.segment[1] - this.contentContainer().v.currentTime) * (1 / this.contentContainer().v.playbackRate));
return Math.max(duration, 4); return Math.max(duration, 4);
@@ -387,7 +392,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
this.adjustDownvotingState(false); this.adjustDownvotingState(false);
// Change the sponsor locally // Change the sponsor locally
let sponsorTime = utils.getSponsorTimeFromUUID(this.contentContainer().sponsorTimes, this.UUID); let sponsorTime = this.getSponsorTime();
if (sponsorTime) { if (sponsorTime) {
if (type === 0) { if (type === 0) {
sponsorTime.hidden = SponsorHideType.Downvoted; sponsorTime.hidden = SponsorHideType.Downvoted;

View File

@@ -532,7 +532,7 @@ function startSponsorSchedule(includeIntersectingSegments: boolean = false, curr
*/ */
function incorrectVideoCheck(videoID?: string, sponsorTime?: SponsorTime): boolean { function incorrectVideoCheck(videoID?: string, sponsorTime?: SponsorTime): boolean {
let currentVideoID = getYouTubeVideoID(document.URL); let currentVideoID = getYouTubeVideoID(document.URL);
if (currentVideoID !== (videoID || sponsorVideoID) || (sponsorTime && !sponsorTimes.includes(sponsorTime))) { if (currentVideoID !== (videoID || sponsorVideoID) || (sponsorTime && (!sponsorTimes || !sponsorTimes.includes(sponsorTime)) && !sponsorTimesSubmitting.includes(sponsorTime))) {
// Something has really gone wrong // 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] The videoID recorded when trying to skip is different than what it should be.");
console.error("[SponsorBlock] VideoID recorded: " + sponsorVideoID + ". Actual VideoID: " + currentVideoID); console.error("[SponsorBlock] VideoID recorded: " + sponsorVideoID + ". Actual VideoID: " + currentVideoID);