Advertisement
CalKalum

Homestuck Pesterlog Simulator.user.js

Apr 9th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Homestuck Pesterlog Simulatior
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2.0
  5. // @description  Simulates the scrolling pesterlog.
  6. // @author       Cal Kalum
  7. // @match        https://www.homestuck.com/story/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. let editingMode = false;
  12. let currentlyEditing = false;
  13. let currentNode = undefined;
  14. let ePressedInsideInput = false;
  15. let spans = [];
  16. let editingColor = "#ff6464";
  17.  
  18. (function() {
  19.     'use strict';
  20.     let pElements = document.getElementsByTagName('p');
  21.     console.log(pElements);
  22.     for(let i = 0; i < pElements.length; i++){
  23.         let spancheck = pElements[i].children;
  24.         for(let j = 0; j < spancheck.length; j++){
  25.             console.log(spancheck[j]);
  26.             if(spancheck[j].tagName === "SPAN"){
  27.                 spans.push(spancheck[j]);
  28.                 spancheck[j].style.transition = "0.3s";
  29.                 spancheck[j].onclick = function(){edit(this)};
  30.             }
  31.         }
  32.     }
  33.     // Your code here...
  34.     let spanIndex = 0;
  35.     document.addEventListener("keyup", function (e) {
  36.         if(e.key ==='a' && !editingMode){
  37.             spans[spanIndex].style.opacity = 1;
  38.             spanIndex++;
  39.         };
  40.         if(e.key ==='e'){
  41.             if(editingMode && currentlyEditing){
  42.                 if(!ePressedInsideInput){
  43.                     if(confirm("You have unsaved changes. Are you sure you want to exit editing mode anyway?")){
  44.                         currentlyEditing = false;
  45.                         editingMode = !editingMode;
  46.                         stopEdit(currentNode, false);
  47.                         document.getElementsByClassName("pos-r")[0].style.backgroundColor = [editingColor, editingColor=document.getElementsByClassName("pos-r")[0].style.backgroundColor][0];
  48.                     }
  49.                 }
  50.             } else {
  51.                 currentlyEditing = false;
  52.                 editingMode = !editingMode;
  53.                 runOnSpans(function(spanIn){spanIn.style.opacity = 1;});
  54.                 document.getElementsByClassName("pos-r")[0].style.backgroundColor = [editingColor, editingColor=document.getElementsByClassName("pos-r")[0].style.backgroundColor][0];
  55.             }
  56.             ePressedInsideInput = false;
  57.         }
  58.         if(e.key ==='r' && !editingMode){
  59.             runOnSpans(function(spanIn){spanIn.style.opacity = 0;});
  60.             spanIndex = 0;
  61.         };
  62.     });
  63. })();
  64.  
  65. function edit (elementIn) {
  66.     console.log("test");
  67.     if(!currentlyEditing && editingMode){
  68.         elementIn.style.display = "none";
  69.         currentlyEditing = true;
  70.         let inputBox = document.createElement("input");
  71.         inputBox.value = elementIn.innerHTML;
  72.         inputBox.style.color = elementIn.style.color;
  73.         inputBox.style.width = "100%";
  74.         inputBox.addEventListener("keydown", function(event) {
  75.             if (event.key === "Enter") {
  76.                 stopEdit(this, true);
  77.             }
  78.             if (event.key === "e") {
  79.                 ePressedInsideInput = true;
  80.             }
  81.         });
  82.         console.log(elementIn.parentNode.offsetWidth);
  83.         elementIn.parentNode.insertBefore(inputBox, elementIn);
  84.         currentNode = elementIn.previousSibling;
  85.         console.log(inputBox);
  86.     }
  87. }
  88.  
  89. function stopEdit (elementIn, save) {
  90.     currentlyEditing = false;
  91.     elementIn.nextSibling.style.display = "inline";
  92.     if(save){elementIn.nextSibling.innerHTML = elementIn.value;}
  93.     elementIn.parentNode.removeChild(elementIn);
  94. }
  95.  
  96. function runOnSpans (functionToRun) {
  97.     for(let i = 0; i < spans.length; i++){
  98.         functionToRun(spans[i]);
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement