ETidalgo
3/20/2019 - 6:37 PM

Fun with JS


Array.from( document.querySelectorAll("button") ).filter(bt => bt.innerText == 'Resolve conversation').forEach(bt => bt.click())

var selector = "button[aria-label=Collapse]";
var collapse = document.querySelectorAll(selector);

Array.from(collapse).forEach(bt => bt.click());

/*
collapse.forEach(x => x.click())
*/

(function(){
    function GetNodesByQuery(querySelector) {
        const nodes = document.querySelectorAll(querySelector);
        return Array.from(nodes);
    }

    function AddCheckboxToElement(element) {
        var checkbox = document.createElement('input');
        checkbox.setAttribute('type', 'checkbox');
        element.appendChild(checkbox);
    }

    function AddCheckboxesToGithubCommitMessages(){
        var commitMessages = GetNodesByQuery('.commit-message') ;    
        commitMessages.forEach(cm => AddCheckboxToElement(cm));    
    }

    AddCheckboxesToGithubCommitMessages();
})();

(function(){
    function GetNodesByQuery(querySelector) {
        const nodes = document.querySelectorAll(querySelector);
        return Array.from(nodes);
    }

    function CreateCheckbox() {
        var checkbox = document.createElement('input');
        checkbox.setAttribute('type', 'checkbox');
        return checkbox;
    }

    function CreateTextInput() {
        var input = document.createElement('input');
        input.setAttribute('type', 'text'); // input.type = 'text'
        // input.setAttribute('name', 'somethingunique');
        return input;
    }

    var elements = GetNodesByQuery('.file-info') ;    
    elements.forEach(el => {
        el.appendChild(CreateCheckbox()); el.appendChild(CreateTextInput()); }
    );
})();
// Needs work
var FibonacciModule = (function() {

    var fib;
    var n1 = 1;
    var n2 = 0;
    var nextFibonacci;

    function fib2AndBeyond(){
        fib = n1 + n2;
        n2 = n1;
        n1 = fib;

        return fib;
    }

    function fib1(){
        nextFibonacci = fib2AndBeyond;
        return 1;
    }

    function fib0(){
        nextFibonacci = fib1;
        return 0;
    }

    nextFibonacci = fib0;

    function wrapperFunction(){
        console.log("wrapperFunction");
        return nextFibonacci();
    }

    return {
        callFibonacciFunctionVariable: nextFibonacci, // permanently assigned to fib0
        callFib2AndBeyond: fib2AndBeyond, // permanently assigned to fib2AndBeyond
        callWrapperFunction: wrapperFunction // calls wrapperFunction 
    }
})();

/*
FibonacciModule.callFibonacciFunctionVariable();
FibonacciModule.callFib2AndBeyond();
FibonacciModule.callWrapperFunction();

*/
  window.generateRandomSlug = () => {
    const disciples = ["Peters", "James", "Johns", "Andrews", "Bartholomews", "Judass", "Judes", "Matthews", "Philips", "Simons", "Thomass"]
    const adjectives = ["other", "new", "good", "high", "old", "great", "big", "American", "small", "large", "national", "young", "different", "long", "little", "important", "political", "bad", "real", "best", "right", "social", "only", "public", "sure", "low", "early", "able", "human", "local", "late", "hard", "major", "better", "economic", "strong", "possible", "whole", "free", "federal", "international", "full", "special", "easy", "clear", "recent", "certain", "personal", "open", "difficult", "available", "likely", "short", "single", "medical", "current", "wrong", "private", "past", "foreign", "fine", "common", "poor", "natural", "significant", "similar", "hot", "dead", "central", "happy", "serious", "ready", "simple", "left", "physical", "general", "environmental", "financial", "blue", "democratic", "dark", "various", "entire", "close", "legal", "religious", "cold", "final", "main", "green", "nice", "huge", "popular", "traditional", "cultural" ]
    const colors = ["red", "blue", "green", "orange", "white", "black", "purple", "utraviolet", "infrared", "yellow", "grey"]
    const tings = ["cup", "phone", "lamp", "plant", "keys", "bottle", "glasses", "pants", "uk-travel-adapter", "railcard", "shirt", "carbon-monoxide-detector", "usb-adaptor", "book", "notepad", "salami", "crisps", "towel", "backpack", "dog", "cat", "platypus", "stingray", "calendar"]
    const slugInput = document.getElementById("practice_slug")
    const prefix = String(document.getElementById("practice_name").value)
    const semiRandomJunk = [randomArrayItem(disciples), randomArrayItem(adjectives), randomArrayItem(colors),randomArrayItem(tings)].join(" ")
    let slug = prefix + " " + semiRandomJunk
    slug = slug.toLowerCase().toLowerCase().split(/\W/).filter(String).join("-")
    slugInput.value = slug
  }
  

(function(){
    function GetNodesByQuery(querySelector) {
        const nodes = document.querySelectorAll(querySelector);
        return Array.from(nodes);
    }

    function CreateCheckbox() {
        var checkbox = document.createElement('input');
        checkbox.setAttribute('class', 'reviewered');
        checkbox.setAttribute('type', 'checkbox');
        checkbox.setAttribute('style', 'margin-left: 20px'); // there may be a better way
        return checkbox;
    }

    function CreateTextInput() {
        var input = document.createElement('input');
        input.setAttribute('class', 'reviewer-comment');
        input.setAttribute('type', 'text'); // input.type = 'text'
        input.setAttribute('style', 'margin-left: 10px; width: 60%;'); // there may be a better way
        // input.setAttribute('name', 'somethingunique');
        return input;
    }

    var githubSelector = '.file-info';
    var devAzureSelector = '.flex-row.flex-grow.justify-end';
    var elements = GetNodesByQuery(devAzureSelector);
    elements.forEach(el => {
        el.appendChild(CreateCheckbox()); 
        el.appendChild(CreateTextInput()); // .style.backgroundColor = "#f5360d"
    });
})();

/* collect comments
comments = document.querySelectorAll(".reviewer-comment");
Array.from(comments).map(el => el.value);

fileSummaries = document.querySelectorAll(".repos-summary-header");
collected = Array.from(fileSummaries).map(fs => { 
    fileName= fs.querySelector("span.text-ellipsis").innerText;
    comment = fs.querySelector(".reviewer-comment").value;
    checked = fs.querySelector('.reviewered').checked;
    return  { "FileName" : fileName, "Comment": comment, "Reviewed": (checked ? 'Reviewed' : 'Not reviewed')}
 });
copy(collected.sort((a, b) => a.FileName.localeCompare(b.FileName)).map(cl => `File[${cl.Reviewed}]: ${cl.FileName} : ${cl.Comment}`).join("\n"));

*/
/* count boxes actually ticked
tickBoxNodes = document.querySelectorAll('.reviewered')
tickBoxes = Array.from(tickBoxNodes)
all = tickBoxes.length
ticked = tickBoxes.filter(a => a.checked).length
'Ticked ' + ticked + ' out of ' + all
*/