Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions stylish-toggle-script.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@

var stylishToggle = stylishToggle = {

selector : 'style.stylish[id*=stylish]',

selector : 'style.stylish-style',
init : function() {
if ( document.querySelectorAll( this.selector ).length ) {
this.addToggle();

setTimeout(() => {
const checkbox = toggle.querySelector('input');
if (checkbox) {
checkbox.checked = false;
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
}
}, 300);
}
},
toggle : function( event ) {
Expand Down Expand Up @@ -63,9 +71,18 @@
'.stylish-toggle-flat:checked + .stylish-toggle-btn:after { left: 50%; background: #7FC6A6; }' +
'</style>';

const policy = trustedTypes.createPolicy('myPolicy', {
createHTML: (input) => {
return input;
}
});
const safeHTML = policy.createHTML(html);

toggle.classList.add( 'stylish-toggle-wrap' );
toggle.title = "Toggle Applied Stylish Theme";
toggle.innerHTML = html;
//toggle.innerHTML = html;
toggle.innerHTML = safeHTML;

document.querySelector( 'body' ).appendChild( toggle );
toggle.querySelector( 'input' ).addEventListener( 'change', this.toggle );
}
Expand Down