Dup Ver Goto 📝

qq

pt2/ 07-31 13:46:39
To
73 lines, 252 words, 2671 chars Monday 2023-07-31 13:46:39

My regular Javascript snippets:

window.q = (x,y=document) => y.querySelector(x)
window.qq = (x,y=document) => Array.from(y.querySelectorAll(x))

or

const q = (x,y=document) => y.querySelector(x)
const qq = (x,y=document) => Array.from(y.querySelectorAll(x))

Jquery CDN

  <script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>

CORS Cross Origin PHP

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT");
header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");

Random stuff

Remove all stylesheets (nice to know this can be done dynamically; probably best to add select)

q("link")
qq("link").forEach(x => x.remove())

Chrome User Scripts (Tampermonkey)

// Generic element killer
(function() {
    'use strict';

    const qq = (x) => Array.from(document.querySelectorAll(x))
    const kl = (x) => qq(x).map((y) => y.parentNode.removeChild(y))
    const kls = (x) => Array.from(x).map(kl)
    const klss = (x) => kls(x.split(" "))
    setInterval(()=>{
        klss("space separated list of selectors")
    },2000)
    // Your code here...
})();
// @name         BBC Football Score in Title Bar
(function() {
    'use strict';
    // usual jquery-lite
    const q = (x,y=document) => y.querySelector(x)
    const qq = (x,y=document) => Array.from(y.querySelectorAll(x))
    // score updater
    const tick = _ => {
        const home = q("section.sp-c-fixture--live-session-header .sp-c-fixture__number--home")
        const away = q("section.sp-c-fixture--live-session-header .sp-c-fixture__number--away")

        const homet = q("section.sp-c-fixture--live-session-header .sp-c-fixture__team-name--home abbr")
        const awayt = q("section.sp-c-fixture--live-session-header .sp-c-fixture__team-name--away abbr")

        const stat = q("section.sp-c-fixture--live-session-header .sp-c-fixture__status--live-sport-light")
        if( home && away && homet && awayt ) {
            document.title = `${home.textContent}-${away.textContent} ${stat.textContent} ${homet.textContent}-${awayt.textContent}`
        }
    }
    setInterval(tick,1000)
})();

Force Font

Some sites have illegible font-faces (illegible on some machines). This hack does a mass-override.

for( x of document.querySelectorAll("*") ) { x.style.fontFamily = "sans-serif" }