Skip to content

Instantly share code, notes, and snippets.

@EnzDev
Last active April 24, 2020 16:22
Show Gist options
  • Save EnzDev/dd002b4fbfd6913f1a8486a39f0836fd to your computer and use it in GitHub Desktop.
Save EnzDev/dd002b4fbfd6913f1a8486a39f0836fd to your computer and use it in GitHub Desktop.

Revisions

  1. EnzDev revised this gist Apr 24, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    // @name @_Ninji insect tracker
    // @description This userscript allows tracking caught and catchable insects on @_Ninji's website page about 1.2.0 update of AC:NH that list impacts on insects spawns.
    // @version 2.1
    // @author github.com/EnzDev
    // @match https://wuffs.org/acnh/insects120.html
    // @grant GM.setValue
    // @grant GM.getValue
  2. EnzDev revised this gist Apr 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name @_Ninji insect tracker
    // @description This userscript allows tracking caught and catchable insects on @_Ninji's website page about 1.2.0 update of AC:NH that list impacts on insects spawns.
    // @version 2.0
    // @version 2.1
    // @match https://wuffs.org/acnh/insects120.html
    // @grant GM.setValue
    // @grant GM.getValue
  3. EnzDev revised this gist Apr 24, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@
    //
    // Icon is @_Ninji profile pic
    // @icon https://pbs.twimg.com/profile_images/1222542119367299073/zHIcvDtZ_400x400.jpg
    //
    // @namespace http://enzomallard.fr/userscripts
    // ==/UserScript==

    // Get the current month
  4. EnzDev revised this gist Apr 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // ==UserScript==
    // @name @_Ninji insect tracker
    // @description This userscript allows tracking caught and caughtable insects on @_Ninji's website page about 1.2.0 update of AC:NH that list impacts on insects spawns.
    // @description This userscript allows tracking caught and catchable insects on @_Ninji's website page about 1.2.0 update of AC:NH that list impacts on insects spawns.
    // @version 2.0
    // @match https://wuffs.org/acnh/insects120.html
    // @grant GM.setValue
  5. EnzDev revised this gist Apr 24, 2020. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    // ==UserScript==
    // @name @_Ninji insect tracker
    // @description This userscript allows tracking caught and caughtable insects on @_Ninji's website page about 1.2.0 update of AC:NH that list impacts on insects spawns.
    // @version 2.0
    // @match https://wuffs.org/acnh/insects120.html
    // @grant GM.setValue
    @@ -35,9 +36,9 @@ const getState = async (name) => {

    const updateStyleForTr = (tr) => {
    if(tr.firstChild.firstChild.checked) {
    tr.classList.add("catch")
    tr.classList.add("caught")
    } else {
    tr.classList.remove("catch")
    tr.classList.remove("caught")
    }

    if(tr.getElementsByClassName(month)[0].textContent != "") {
    @@ -61,7 +62,7 @@ $$("tbody tr").splice(1).forEach(async (tr) => {
    tr.insertBefore(d, tr.firstChild)

    if(checkbox.checked) {
    tr.classList.add("catch")
    tr.classList.add("caught")
    }
    })

    @@ -94,14 +95,14 @@ const pairMonthRule = (rules) => ["jan","mar","may","jul","sep","nov"]

    sheet.insertRule('tbody > tr:nth-child(5n+1) > td { border-bottom: solid 5px #666; }')

    // catch && not available => lightgreen
    sheet.insertRule(`.catch:not(.available) { background: lightgreen !important; }`)
    sheet.insertRule(`${pairMonthRule('.catch:not(.available)')} { background: #cfc !important; }`)
    // caught && not available => lightgreen
    sheet.insertRule(`.caught:not(.available) { background: lightgreen !important; }`)
    sheet.insertRule(`${pairMonthRule('.caught:not(.available)')} { background: #cfc !important; }`)

    // catch && available => lightblue
    sheet.insertRule(`.catch.available { background: lightblue !important; }`)
    sheet.insertRule(`${pairMonthRule('.catch.available')} { background: #def !important; }`)
    // caught && available => lightblue
    sheet.insertRule(`.caught.available { background: lightblue !important; }`)
    sheet.insertRule(`${pairMonthRule('.caught.available')} { background: #def !important; }`)

    // available && not catch => lightcoral
    sheet.insertRule(`.available:not(.catch) { background: lightcoral !important; }`)
    sheet.insertRule(`${pairMonthRule('.available:not(.catch)')} { background: #faa !important; }`)
    // available && not caught => lightcoral
    sheet.insertRule(`.available:not(.caught) { background: lightcoral !important; }`)
    sheet.insertRule(`${pairMonthRule('.available:not(.caught)')} { background: #faa !important; }`)
  6. EnzDev revised this gist Apr 24, 2020. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -88,8 +88,7 @@ document.head.appendChild(styleEl)

    const sheet = styleEl.sheet;

    const pairMonthRule = (rules) => "jan mar may jul sep nov"
    .split(" ")
    const pairMonthRule = (rules) => ["jan","mar","may","jul","sep","nov"]
    .map(month => `${rules} .${month}`)
    .join(", ")

  7. EnzDev revised this gist Apr 24, 2020. 1 changed file with 17 additions and 16 deletions.
    33 changes: 17 additions & 16 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    // ==UserScript==
    // @name @_Ninji insect tracker
    // @version 1.9
    // @version 2.0
    // @match https://wuffs.org/acnh/insects120.html
    // @grant unsafeWindow
    // @grant GM.setValue
    // @grant GM.getValue
    // @noframes
    // @run-at document-end
    // @run-at document-end
    //
    // Icon is @_Ninji profile pic
    // @icon https://pbs.twimg.com/profile_images/1222542119367299073/zHIcvDtZ_400x400.jpg
    // @icon https://pbs.twimg.com/profile_images/1222542119367299073/zHIcvDtZ_400x400.jpg
    // ==/UserScript==

    // Get the current month
    @@ -23,14 +24,13 @@ const makeNode = ((type, attrs) => {
    // Update thr storage when the input change
    const updateStorage = (e)=>{
    let input = e.target
    unsafeWindow.localStorage.setItem(input.value, input.checked ? 1 : 0)
    GM.setValue(input.value, input.checked ? 1 : 0)
    updateStyleForTr(input.parentElement.parentElement)
    }

    const getState = (name) => {
    let state = unsafeWindow.localStorage.getItem(name)
    if(state == undefined) unsafeWindow.localStorage.setItem(name, 0)
    return parseInt(unsafeWindow.localStorage.getItem(name)) ? true : false
    const getState = async (name) => {
    let state = await GM.getValue(name, 0)
    return state === 1 ? true : false
    }

    const updateStyleForTr = (tr) => {
    @@ -47,14 +47,15 @@ const updateStyleForTr = (tr) => {
    }
    }

    // Immitate browser $$ function
    const $$ = (it) => Array.from(document.querySelectorAll(it))

    // Create the checkboxes for each insect
    $$("tbody tr").splice(1).forEach((tr) => {
    $$("tbody tr").splice(1).forEach(async (tr) => {
    let d = makeNode("td",{})
    let name = tr.getElementsByClassName("insectname")[0].innerText
    let checkbox = makeNode("input", {"type":"checkbox", "value":name})
    checkbox.checked = getState(name)
    checkbox.checked = await getState(name)
    checkbox.onchange = updateStorage
    d.append(checkbox)
    tr.insertBefore(d, tr.firstChild)
    @@ -80,28 +81,28 @@ $$(`.${month}`).forEach((month) => {
    if(month.textContent != "") month.parentElement.classList.add("available")
    })

    // Stylling
    const styleEl = document.createElement("style")
    styleEl.appendChild(document.createTextNode(""))
    document.head.appendChild(styleEl)

    const sheet = styleEl.sheet;

    const bitches = (rules) => "jan mar may jul sep nov"
    const pairMonthRule = (rules) => "jan mar may jul sep nov"
    .split(" ")
    .map(month => `${rules} .${month}`)
    .join(", ")

    // sheet.insertRule(`.${month} { background: lightblue !important; }`)
    sheet.insertRule('tbody > tr:nth-child(5n+1) > td { border-bottom: solid 5px #666; }')

    // catch && not available => lightgreen
    sheet.insertRule(`.catch:not(.available) { background: lightgreen !important; }`)
    sheet.insertRule(`${bitches('.catch:not(.available)')} { background: #cfc !important; }`)
    sheet.insertRule(`${pairMonthRule('.catch:not(.available)')} { background: #cfc !important; }`)

    // catch && available => lightblue
    sheet.insertRule(`.catch.available { background: lightblue !important; }`)
    sheet.insertRule(`${bitches('.catch.available')} { background: #def !important; }`)
    sheet.insertRule(`${pairMonthRule('.catch.available')} { background: #def !important; }`)

    // available && not catch => lightcoral
    sheet.insertRule(`.available:not(.catch) { background: lightcoral !important; }`)
    sheet.insertRule(`${bitches('.available:not(.catch)')} { background: #faa !important; }`)
    sheet.insertRule(`${pairMonthRule('.available:not(.catch)')} { background: #faa !important; }`)
  8. EnzDev revised this gist Apr 24, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -70,10 +70,12 @@ head.insertBefore(makeNode("th", {}), head.firstChild)

    // Remove old values
    $$("s").forEach(it => it.remove())
    // Set new values as main text
    $$("b").forEach(it => {
    it.parentElement.innerText = it.innerText
    })

    // If the month have a textContent, it is available
    $$(`.${month}`).forEach((month) => {
    if(month.textContent != "") month.parentElement.classList.add("available")
    })
  9. EnzDev revised this gist Apr 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    // @noframes
    // @run-at document-end
    //
    // @_Ninji profile pic
    // Icon is @_Ninji profile pic
    // @icon https://pbs.twimg.com/profile_images/1222542119367299073/zHIcvDtZ_400x400.jpg
    // ==/UserScript==

  10. EnzDev created this gist Apr 24, 2020.
    105 changes: 105 additions & 0 deletions ninji_insect_tracker.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    // ==UserScript==
    // @name @_Ninji insect tracker
    // @version 1.9
    // @match https://wuffs.org/acnh/insects120.html
    // @grant unsafeWindow
    // @noframes
    // @run-at document-end
    //
    // @_Ninji profile pic
    // @icon https://pbs.twimg.com/profile_images/1222542119367299073/zHIcvDtZ_400x400.jpg
    // ==/UserScript==

    // Get the current month
    const month = (new Date()).toLocaleDateString('en-US', { month: 'short' }).toLowerCase()

    // Tool to create a node with object of attributes
    const makeNode = ((type, attrs) => {
    let node = document.createElement(type);
    let attributes = Object.entries(attrs).forEach(([t, v]) => node.setAttribute(t, v));
    return node;
    })

    // Update thr storage when the input change
    const updateStorage = (e)=>{
    let input = e.target
    unsafeWindow.localStorage.setItem(input.value, input.checked ? 1 : 0)
    updateStyleForTr(input.parentElement.parentElement)
    }

    const getState = (name) => {
    let state = unsafeWindow.localStorage.getItem(name)
    if(state == undefined) unsafeWindow.localStorage.setItem(name, 0)
    return parseInt(unsafeWindow.localStorage.getItem(name)) ? true : false
    }

    const updateStyleForTr = (tr) => {
    if(tr.firstChild.firstChild.checked) {
    tr.classList.add("catch")
    } else {
    tr.classList.remove("catch")
    }

    if(tr.getElementsByClassName(month)[0].textContent != "") {
    tr.classList.add("available")
    } else {
    tr.classList.remove("available")
    }
    }

    const $$ = (it) => Array.from(document.querySelectorAll(it))

    // Create the checkboxes for each insect
    $$("tbody tr").splice(1).forEach((tr) => {
    let d = makeNode("td",{})
    let name = tr.getElementsByClassName("insectname")[0].innerText
    let checkbox = makeNode("input", {"type":"checkbox", "value":name})
    checkbox.checked = getState(name)
    checkbox.onchange = updateStorage
    d.append(checkbox)
    tr.insertBefore(d, tr.firstChild)

    if(checkbox.checked) {
    tr.classList.add("catch")
    }
    })

    // Add a space for the header
    const head = $$("tbody tr")[0]
    head.insertBefore(makeNode("th", {}), head.firstChild)

    // Remove old values
    $$("s").forEach(it => it.remove())
    $$("b").forEach(it => {
    it.parentElement.innerText = it.innerText
    })

    $$(`.${month}`).forEach((month) => {
    if(month.textContent != "") month.parentElement.classList.add("available")
    })

    const styleEl = document.createElement("style")
    styleEl.appendChild(document.createTextNode(""))
    document.head.appendChild(styleEl)

    const sheet = styleEl.sheet;

    const bitches = (rules) => "jan mar may jul sep nov"
    .split(" ")
    .map(month => `${rules} .${month}`)
    .join(", ")

    // sheet.insertRule(`.${month} { background: lightblue !important; }`)
    sheet.insertRule('tbody > tr:nth-child(5n+1) > td { border-bottom: solid 5px #666; }')

    // catch && not available => lightgreen
    sheet.insertRule(`.catch:not(.available) { background: lightgreen !important; }`)
    sheet.insertRule(`${bitches('.catch:not(.available)')} { background: #cfc !important; }`)

    // catch && available => lightblue
    sheet.insertRule(`.catch.available { background: lightblue !important; }`)
    sheet.insertRule(`${bitches('.catch.available')} { background: #def !important; }`)

    // available && not catch => lightcoral
    sheet.insertRule(`.available:not(.catch) { background: lightcoral !important; }`)
    sheet.insertRule(`${bitches('.available:not(.catch)')} { background: #faa !important; }`)