// ==UserScript==
// @name SHKOLO dark mode
// @namespace Violentmonkey Scripts
// @match https://app.shkolo.bg/*
// @grant GM_setValue
// @grant GM_getValue
// @version 1.43
// @author RedTTG
// @run-at document-body
// @license MIT
// @description 12/3/2021, 10:31:05 AM
// ==/UserScript==
var version = "1.43"
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
// DEFAULT COLOR VALUES
var dc_dark = "#202040";
var dc_light = "#404080";
var dc_blind = "#6060A0";
var dc_blinding = "#A0A0FA";
var dc_red = "#F02F2F";
// INIT MOD
function initSettingElements() {
initGMStorage();
}
document.addEventListener("DOMContentLoaded", function(){
initMenu();
if (url.indexOf("customize") > -1){
initCustomize();
}
});
// INIT VALUES
function initGMStorage(reset = false) {
if (!GM_getValue("colorVeryDark") || reset) {
GM_setValue("colorVeryDark", dc_dark);
}
if (!GM_getValue("colorDark") || reset) {
GM_setValue("colorDark", dc_light);
}
if (!GM_getValue("colorLight") || reset) {
GM_setValue("colorLight", dc_blind);
}
if (!GM_getValue("colorVeryLight") || reset) {
GM_setValue("colorVeryLight", dc_blinding);
}
if (!GM_getValue("colorRed") || reset) {
GM_setValue("colorRed", dc_red);
}
}
function initMenu() {
x = document.getElementsByClassName('sub-menu');
for(i = 0; i < x.length; i++){
if (x[i].parentNode.children[0].children[1].textContent != "Администрация"){
console.log(x[i].parentNode.children[0].children[1].textContent);
continue;
}
var tag = document.createElement('h5');
var text = document.createTextNode("DARK MODE :)");
tag.appendChild(text);
tag.classList.add('menu-title');
x[i].appendChild(tag);
tag = document.createElement('li');
var tag2 = document.createElement('a');
tag2.href = '/customize';
tag2.id = 'settingsDarkId';
tag2.classList.add('nav-link');
var tag3 = document.createElement('i');
tag3.classList.add('far');
tag3.classList.add('fa-dark');
text = document.createTextNode(' Customize');
tag2.appendChild(tag3);
tag2.appendChild(text);
tag.appendChild(tag2);
x[i].appendChild(tag);
}
}
function initCustomize(){
x = document.getElementsByClassName('page-404');
var parent;
for(i = 0; i < x.length; i++){
parent = x[i].parentNode;
x[i].parentNode.removeChild(x[i]);
}
var tag = document.createElement('div');
// ADD COLORS
var index = 0
tag.appendChild(generateColorPicker(c_dark, 'h3', 'Very Dark color....', 'c_dark', index));index++;
tag.appendChild(generateColorPicker(c_light, 'h3', 'Dark color....', 'c_light', index));index++;
tag.appendChild(generateColorPicker(c_blind, 'h3', 'Light color....', 'c_blind', index));index++;
tag.appendChild(generateColorPicker(c_blinding, 'h3', 'Very Light color....', 'c_blinding', index));index++;
tag.appendChild(generateColorPicker(c_red, 'h3', 'Red color....', 'c_red', index));index++;
// ADD SUBMIT BUTTONS
var button_1 = document.createElement('button'); var button_2 = document.createElement('button'); // Make buttons
button_1.style.position = 'absolute'; button_2.style.position = 'absolute';
var topv = 20+index*12;
var lowv = 225-index*12;
button_1.style.top = topv+'px'; button_2.style.top = lowv+'px';
button_1.style.left = '350px'; button_2.style.left = '350px';
var text = document.createTextNode('Save Changes');
button_1.appendChild(text);
text = document.createTextNode('Reset');
button_2.appendChild(text);
button_1.classList.add('darkButton'); button_2.classList.add('darkButton'); // Add class to buttons
tag.appendChild(button_1); tag.appendChild(button_2); // Apply buttons to customization menu
// BUTTON ACTION
button_1.onclick = function(){customizeSave();refreshPage();};
button_2.onclick = function(){initGMStorage(true);refreshPage();};
// FINISH OFF
tag.classList.add('customizeMenu');
parent.appendChild(tag);
}
function generateColorPicker(color = "#000000", tag = "h1", text = "Color Picker", id = null, index = 0){
var input = document.createElement('input');
var textTag = document.createElement(tag);
var textNode = document.createTextNode(text);
textTag.appendChild(textNode);
input.type = 'color';
input.value = color;
input.style.position = 'absolute';
var y = 32+50*index
input.style.top = y+'px';
input.style.left = '250px';
if (id != null){
input.id = id;
}
textTag.appendChild(input);
textTag.classList.add('colorPicker');
return textTag
}
function customizeSave(){
dc_dark = document.getElementById('c_dark').value;
dc_light = document.getElementById('c_light').value;
dc_blind = document.getElementById('c_blind').value;
dc_blinding = document.getElementById('c_blinding').value;
dc_red = document.getElementById('c_red').value;
initGMStorage(true);
}
function refreshPage(){
window.location.reload();
}
// LOAD VALUES
initSettingElements()
var c_dark = GM_getValue("colorVeryDark");
var c_light = GM_getValue("colorDark");
var c_blind = GM_getValue("colorLight");
var c_blinding = GM_getValue("colorVeryLight");
var c_red = GM_getValue("colorRed");
// LOAD CSS
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'https://redttg.pythonanywhere.com/'+c_dark.replace('#','')+'/'+c_light.replace('#','')+'/'+c_blind.replace('#','')+'/'+c_blinding.replace('#','')+'/'+c_red.replace('#','')+'/dashboard.css';
link.media = 'all';
head.appendChild(link);
//
var url = window.location.href;
// CHECK AND HACK PAGE
if(url.indexOf("dashboard") > -1){
var x = document.getElementsByClassName("page-header");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
x = document.getElementsByClassName("page-footer");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
x = document.getElementsByClassName("col-md-12");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
x = document.getElementsByClassName("col-sm-6");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
}
else if(url.indexOf("diary") > -1){
var x = document.getElementsByClassName("page-header");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
x = document.getElementsByClassName("page-footer");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_dark;
}
x = document.getElementsByClassName("portlet light gradesBody");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_light;
x[i].style.color = c_blind;
}
}
else if (url.indexOf("test/result") > -1){
}
else if (url.indexOf("app.shkolo.bg") > -1){
var x = document.getElementsByClassName("tab-content");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_blind;
}
x = document.getElementsByClassName("auth-tabs");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = c_light;
}
x = document.getElementsByClassName("or-login-text");
for(i = 0; i < x.length; i++){
if (x[i].firstElementChild.nodeName == "H4")
{
x[i].firstElementChild.firstElementChild.style.backgroundColor = c_blind;
}
}
x = document.getElementsByClassName("auth-tabs");
for(i = 0; i < x.length; i++){
for(kid = 0; kid < x[i].children.length; kid++)
{
if (x[i].children[kid].nodeName == "LI")
{
x[i].children[kid].firstElementChild.style.backgroundColor = c_light;
}
}
}
x = document.getElementsByClassName("phone-label");
for(i = 0; i < x.length; i++){
x[i].style.setProperty("background-color", c_light, "important");
}
//btn btn-xs btn-custom-primary
x = document.getElementsByClassName("btn-custom-primary");
for(i = 0; i < x.length; i++){
x[i].style.setProperty("background-color", c_light, "important");
}
}
else {
console.log("Couldn't find dark mode mod for this page of shkolo, anything besides the background and side menus might be broken.");
console.log("Or it could be it doesn't need javascript, and css is enough, in which case enjoy!");
}
//
console.log("Shkolo dark mode, checking for updates...")
var urls = "https://greasyfork.org/en/scripts/436501-shkolo-dark-mode";
fetch(urls)
.then(function(response) {
return response.text();
}).then(function(data) {
if (data.includes("<dd class=\"script-show-version\"><span>"+version+"</span></dd>")){
console.log("no update found!");
}
else {console.log("update avaliable!");window.open("https://greasyfork.org/scripts/436501-shkolo-dark-mode/code/SHKOLO dark mode.user.js","_blank").focus();}
});
console.log("Shkolo Dark Mode finished running for this page.");
console.log("Thanks for download!");