<commit_before>// ==UserScript==
// @name           Style shiroyukitranslations
// @description    Change interface on shiroyukitranslations.com
// @author         HK49
// @include        http://shiroyukitranslations.com/*
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/hide_inactive_mouse.js
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/waitress.js
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/indent.js
// @version        0.32
// @updateURL      https://github.com/HK49/tampermonkey-plugins/raw/stable/shiroyuki.js
// @downloadURL    https://github.com/HK49/tampermonkey-plugins/raw/stable/shiroyuki.js
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.
//- The "@run-at document-start" directive is needed for script execution before the page render.

// restore #main bg color from cache or assign standart
var saveBG = localStorage.saveBG || 'rgb(90, 90, 92)';


function colorManager() {
  // window.main is already should be declared by style, but safeguard
  var main = document.getElementById('main') || null;

  // if #main style changes - also change style of body, #page and p
  var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function() {
      colorManager();
    });
  });

  if(main) {
    // update saveBG; getComputedStyle gets rgb of backgroundColor
    saveBG = window.getComputedStyle(main).backgroundColor || saveBG;

    // getter and setter
    var oldStyle = saveBG.match(/\d+/g), newStyle = [];
    // make #page and body darker or lighter then #main
    for(var i = 0; i < oldStyle.length; i++) {
      newStyle.push((+oldStyle[i] > 60 && +oldStyle[i] - 60) || +oldStyle[i] + 20);
    }
    waitress('#page, body', { background: 'rgb(' + newStyle.join(', ') + ')' });

    // get sum of r g b
    var rgbSum = oldStyle.reduce(function(a, b) { return +a + +b; }, 0);
    // change text color depending on #main bg color
    var txt = { green: 'rgb(100, 155, 100)', dark: 'rgb(30, 30, 30)', warm: 'rgb(80, 50, 26)' };
    waitress('p', {
      color: (
        (rgbSum === 718 ? txt.warm : rgbSum > 600 ? txt.dark : rgbSum < 90 ? txt.green : '')
        + '!important'
      )
    });

    if(!main.observing) {
      observer.observe(main, { attributes: true, attributeFilter: ['style'] });
      observer.observe(document.body, { attributes: true, attributeFilter: ['style'] });
      main.observing = true;
    }
  } else {
    // wait for #main to execute this func
    window.requestAnimationFrame(colorManager);
  }
}

function shiroyukiMainFunc() {
  waitress('#main', { background: saveBG, padding: '10%', textAlign: 'justify' }, colorManager());
  waitress('#page', { boxShadow: '0 0 50px hsla(0, 0%, 0%, 0.3)', width: '80%', maxWidth: '210mm' });
  waitress('#page:before, #page:after', { width: '100% !important' });
  waitress('p', { fontSize: '1.3rem', lineHeight: '1.8rem' });
  waitress('#sidebar', { display: 'none' });
  waitress('#primary', { width: '100%' });
  waitress('body', { scrollbarZIndex: '9e99' });
}

if(window.location.host.includes("shiroyukitranslations")) {
  shiroyukiMainFunc();
}

document.addEventListener('readystatechange', function() {
  if(document.readyState === "complete") {
    // hide mouse if not moving (kinda)
    mouse.hide();

    // add indent on long paragraphs
    addIndent(document.getElementsByTagName('p'));
  }<commit_msg>shiroyuki full screen mode and changed observer<commit_after>/* global waitress, mouse, addIndent */

// ==UserScript==
// @name           Style shiroyukitranslations
// @description    Change interface on shiroyukitranslations.com
// @author         HK49
// @include        http://shiroyukitranslations.com/*
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/hide_inactive_mouse.js
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/waitress.js
// @require        https://github.com/HK49/tampermonkey-plugins/raw/stable/libs/indent.js
// @version        0.32
// @updateURL      https://github.com/HK49/tampermonkey-plugins/raw/stable/shiroyuki.js
// @downloadURL    https://github.com/HK49/tampermonkey-plugins/raw/stable/shiroyuki.js
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.
//- The "@run-at document-start" directive is needed for script execution before the page render.

// restore #main bg color from cache or assign standart
var saveBG = localStorage.saveBG || 'rgb(90, 90, 92)';


function colorManager() {
  // window.main is already should be declared by style, but safeguard
  var main = document.getElementById('main') || null;

  // if #main style changes - also change style of body, #page and p
  var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function() {
      colorManager();
    });
  });

  if(main) {
    // update saveBG; getComputedStyle gets rgb of backgroundColor
    saveBG = window.getComputedStyle(main).backgroundColor || saveBG;

    // getter and setter
    var oldStyle = saveBG.match(/\d+/g), newStyle = [];
    // make #page and body darker or lighter then #main
    for(var i = 0; i < oldStyle.length; i++) {
      newStyle.push((+oldStyle[i] > 60 && +oldStyle[i] - 60) || +oldStyle[i] + 20);
    }
    waitress('#page, body', { background: 'rgb(' + newStyle.join(', ') + ')' });

    // get sum of r g b
    var rgbSum = oldStyle.reduce(function(a, b) { return +a + +b; }, 0);
    // change text color depending on #main bg color
    var txt = { green: 'rgb(100, 155, 100)', dark: 'rgb(30, 30, 30)', warm: 'rgb(80, 50, 26)' };
    waitress('p, #btn_full', {
      color: (
        (rgbSum === 718 ? txt.warm : rgbSum > 600 ? txt.dark : rgbSum < 90 ? txt.green : '')
        + '!important'
      )
    });

    if(!main.observing) {
      observer.observe(main, { attributes: true, attributeFilter: ['style'] });
      observer.observe(document.getElementById('page'), { attributes: true, attributeFilter: ['style'] });
      main.observing = true;
    }
  } else {
    // wait for #main to execute this func
    window.requestAnimationFrame(colorManager);
  }
}

function shiroyukiMainFunc() {
  waitress('#main', { background: saveBG, padding: '10%', textAlign: 'justify' }, colorManager());
  waitress('#page', { boxShadow: '0 0 50px hsla(0, 0%, 0%, 0.3)', width: '80%', maxWidth: '210mm' });
  waitress('#page::before, #page::after', { width: '100% !important' });
  waitress('p', { fontSize: '1.3rem', lineHeight: '1.8rem' });
  waitress('#sidebar', { display: 'none' });
  waitress('#primary', { width: '100%' });
  waitress('body', { scrollbarZIndex: '9e99' });
}

if(window.location.host.includes("shiroyukitranslations")) {
  shiroyukiMainFunc();
}

function fullScreen() {
  var screenFull, req;
  var btn = document.body.insertBefore(document.createElement("btn"), document.body.firstElementChild);

  btn.setAttribute("id", "btn_full");
  Object.assign(btn.style, {
    position: 'fixed',
    bottom: '10px',
    left: '10px',
    width: '26px',
    height: '26px',
    border: 'solid 2px',
    cursor: 'pointer'
  });
  document.getElementsByTagName("html")[0].style.backgroundColor = document.body.style.background;
  document.head.insertAdjacentHTML('beforeend', "<style name=fullscreen'>body:-webkit-full-screen { overflow-y: scroll; background-color: " + document.body.style.background + "; width:100%; height:100%; }</style>");

  waitress("#btn_full::before, #btn_full::after", { content: '\'\'', width: '0', height: '0', position: 'absolute', borderTopColor: 'transparent', borderBottomColor: 'transparent', borderStyle: 'solid', transition: "all .3s ease-in-out" });
  waitress("#btn_full::before", { left: '3px', bottom: '3px', borderWidth: '10px 0 0 10px' });
  waitress("#btn_full::after", { right: '3px', top: '3px', borderWidth: '0 10px 10px 0' });
  waitress("#btn_full:hover::before", { left: '1px', bottom: '1px' });
  waitress("#btn_full:hover::after", { right: '1px', top: '1px' });

  var action = function(o) {
    if(!screenFull) {
      req = o.requestFullScreen || o.webkitRequestFullscreen || o.mozRequestFullScreen || o.msRequestFullscreen;
      screenFull = true;
      req.apply(o);
    } else {
      req = document.exitFullscreen || document.webkitExitFullscreen || document.mozExitFullScreen || document.msExitFullscreen;
      screenFull = false;
      req.bind(document).apply();
    }
  };
  btn.addEventListener('click', function(){ action(document.body); });
}

document.addEventListener('readystatechange', function() {
  if(document.readyState === "complete") {
    // hide mouse if not moving (kinda)
    mouse.hide();

    // add indent on long paragraphs
    addIndent(document.getElementsByTagName('p'));

    fullScreen();
  }
{'fraction_non_alphanumeric': 0.16888640179071068, 'fraction_numerical': 0.0238388360380526, 'mean_word_length': 3.54989816700611, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3771550', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2862, 'n_words': 680}