mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 21:17:20 +03:00
Auto update hidden categories when redeemed
This commit is contained in:
@@ -38,10 +38,21 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
|
|||||||
this.setState({
|
this.setState({
|
||||||
hideChapter: !allowed
|
hideChapter: !allowed
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): React.ReactElement {
|
render(): React.ReactElement {
|
||||||
|
if (this.state.hideChapter) {
|
||||||
|
// Ensure force update refreshes this
|
||||||
|
fetchingChaptersAllowed().then((allowed) => {
|
||||||
|
if (allowed) {
|
||||||
|
this.setState({
|
||||||
|
hideChapter: !allowed
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let defaultOption = "disable";
|
let defaultOption = "disable";
|
||||||
// Set the default opton properly
|
// Set the default opton properly
|
||||||
for (const categorySelection of Config.config.categorySelections) {
|
for (const categorySelection of Config.config.categorySelections) {
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ import UnsubmittedVideos from "./render/UnsubmittedVideos";
|
|||||||
import KeybindComponent from "./components/options/KeybindComponent";
|
import KeybindComponent from "./components/options/KeybindComponent";
|
||||||
import { showDonationLink } from "./utils/configUtils";
|
import { showDonationLink } from "./utils/configUtils";
|
||||||
import { localizeHtmlPage } from "./utils/pageUtils";
|
import { localizeHtmlPage } from "./utils/pageUtils";
|
||||||
|
import { StorageChangesObject } from "./types";
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
let embed = false;
|
let embed = false;
|
||||||
|
|
||||||
|
const categoryChoosers: CategoryChooser[] = [];
|
||||||
|
const unsubmittedVideos: UnsubmittedVideos[] = [];
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', init);
|
window.addEventListener('DOMContentLoaded', init);
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
@@ -291,10 +295,10 @@ async function init() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "react-CategoryChooserComponent":
|
case "react-CategoryChooserComponent":
|
||||||
new CategoryChooser(optionsElements[i]);
|
categoryChoosers.push(new CategoryChooser(optionsElements[i]));
|
||||||
break;
|
break;
|
||||||
case "react-UnsubmittedVideosComponent":
|
case "react-UnsubmittedVideosComponent":
|
||||||
new UnsubmittedVideos(optionsElements[i])
|
unsubmittedVideos.push(new UnsubmittedVideos(optionsElements[i]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,10 +356,8 @@ async function shouldHideOption(element: Element): Promise<boolean> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the config is updated
|
* Called when the config is updated
|
||||||
*
|
|
||||||
* @param {String} element
|
|
||||||
*/
|
*/
|
||||||
function optionsConfigUpdateListener() {
|
function optionsConfigUpdateListener(changes: StorageChangesObject) {
|
||||||
const optionsContainer = document.getElementById("options");
|
const optionsContainer = document.getElementById("options");
|
||||||
const optionsElements = optionsContainer.querySelectorAll("*");
|
const optionsElements = optionsContainer.querySelectorAll("*");
|
||||||
|
|
||||||
@@ -364,9 +366,16 @@ function optionsConfigUpdateListener() {
|
|||||||
case "display":
|
case "display":
|
||||||
updateDisplayElement(<HTMLElement> optionsElements[i])
|
updateDisplayElement(<HTMLElement> optionsElements[i])
|
||||||
break;
|
break;
|
||||||
case "react-UnsubmittedVideosComponent":
|
}
|
||||||
new UnsubmittedVideos(optionsElements[i])
|
}
|
||||||
break;
|
|
||||||
|
if (changes.categorySelections || changes.payments) {
|
||||||
|
for (const chooser of categoryChoosers) {
|
||||||
|
chooser.update();
|
||||||
|
}
|
||||||
|
} else if (changes.unsubmittedSegments) {
|
||||||
|
for (const chooser of unsubmittedVideos) {
|
||||||
|
chooser.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,20 @@ import CategoryChooserComponent from "../components/options/CategoryChooserCompo
|
|||||||
|
|
||||||
class CategoryChooser {
|
class CategoryChooser {
|
||||||
|
|
||||||
|
ref: React.RefObject<CategoryChooserComponent>;
|
||||||
|
|
||||||
constructor(element: Element) {
|
constructor(element: Element) {
|
||||||
|
this.ref = React.createRef();
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<CategoryChooserComponent/>,
|
<CategoryChooserComponent ref={this.ref} />,
|
||||||
element
|
element
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(): void {
|
||||||
|
this.ref.current?.forceUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CategoryChooser;
|
export default CategoryChooser;
|
||||||
@@ -4,12 +4,21 @@ import UnsubmittedVideosComponent from "../components/options/UnsubmittedVideosC
|
|||||||
|
|
||||||
class UnsubmittedVideos {
|
class UnsubmittedVideos {
|
||||||
|
|
||||||
|
ref: React.RefObject<UnsubmittedVideosComponent>;
|
||||||
|
|
||||||
constructor(element: Element) {
|
constructor(element: Element) {
|
||||||
|
this.ref = React.createRef();
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<UnsubmittedVideosComponent/>,
|
<UnsubmittedVideosComponent ref={this.ref} />,
|
||||||
element
|
element
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(): void {
|
||||||
|
this.ref.current?.forceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UnsubmittedVideos;
|
export default UnsubmittedVideos;
|
||||||
|
|||||||
Reference in New Issue
Block a user