Switch Facebook's theme to match the system
Устаревшая версия за
// ==UserScript==
// @name Facebook Dark Theme Sync
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Switch Facebook's theme to match the system
// @author You
// @match https://www.facebook.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
$( document ).ready(function() {
let systemDarkEnabled = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
let isDarkEnabled = $('body').html().indexOf('["CometDarkModeSetting",[],{"initialSetting":"ENABLED"}') != -1;
console.log("systemDarkEnabled " + systemDarkEnabled + " isDarkEnabled " + isDarkEnabled);
//Check if themes are not in sync
if(systemDarkEnabled != isDarkEnabled){
//Open account menu
let accountMenu = $("[aria-label=Account]");
accountMenu.click();
console.log("account menu clicked");
setTimeout(function() {
//Open theme switcher
let switcher = $("span:contains('Display & Accessibility')").last();
switcher.click();
//Delay a second to allow the menu to open
setTimeout(function() {
let darkModeMenu = $("[aria-label=\"Dark Mode\"]");
//Click the appropriate radio button
if(systemDarkEnabled){
darkModeMenu.children().first().next().children().first().click()
}else{
darkModeMenu.children().first().children().first().click()
}
}, 1000);
}, 2500);
}
});
})();