Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View netsi1964's full-sized avatar

Sten Hougaard netsi1964

View GitHub Profile
@netsi1964
netsi1964 / samples.json
Last active July 28, 2023 13:28
Test your CSS selector skills
[
{
"pattern": "h1~div:first-of-type .button[data-type=\"submit\"]:not(.disabled)",
"description": "Selects an element with class 'button' and data attribute 'data-type' set to 'submit', that is also not 'disabled', which is a descendant of the first element of type 'div' that comes after an 'h1' element.",
"elementName": "",
"classes": [
"button"
],
"example": "\t<h1>Title</h1>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"submit\">Submit</button>\r\n\t</div>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"cancel\">Cancel</button>\r\n\t</div>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"submit\" disabled>Disabled</button>\r\n\t</div>",
"note": ""
@netsi1964
netsi1964 / generate_prompt_quiz.js
Last active June 25, 2023 13:59
Generate ChatGPT fun quiz from dr.dk
if (document.location.href.includes("dr.dk")) {
// Reading (bad) news can be hard.
// This script you should run in the console and then hover over headlines to get a new random headline.
// Simply copy it
// Open developer toolbar (press F12)
// In the "console" paste the script, press ENTER
// Enjoy! Simply hover over a headline to get a new random text :-)
// Try reading it seeing the photo together with the new random text
// THIS VERSION is for https://www.dr.dk
//
@netsi1964
netsi1964 / Geometry.js
Last active May 20, 2023 08:08
A useful class when working with Geometry
/**
* A class for basic geometric calculations.
*/
export default class Geometry {
static PI = 3.141592653589793;
static circleArea(radius) {
if (radius < 0) {
throw new Error("Radius cannot be negative");
@netsi1964
netsi1964 / scrollmania.js
Created September 19, 2022 12:15
Pretend that scrolling around a page happens :-)
let all = Array.from(document.querySelectorAll('*'));
setInterval(() => {
all[Math.floor(Math.random()*all.length)].scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"})
}, 800)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@netsi1964
netsi1964 / svg-utils.js
Last active April 18, 2022 07:09
Some SVG utils
export screen2svg = (eleSvg, x, y) => {
const point = eleSvg.createSVGPoint();
point.x = x;
point.y = y;
return point.matrixTransform(eleSvg.getScreenCTM().inverse());
}
@netsi1964
netsi1964 / funheadlines.js
Created March 10, 2022 20:55
Make news fun again
var tags = Array.from(document.querySelectorAll('*')).filter(ele => !/^(a|script|iframe|title|meta|head|body|style|html|link|svg|path|g|button|img|picture|ol|ul|source|nav)$/ig.exec(ele.tagName));
var temp = tags.reduce((sum, curr) => {
const tag = curr.tagName;
const len = curr.textContent.length;
if (sum[tag]) {
sum[tag].len += len;
sum[tag].count++;
} else {
sum[tag] = { len, count:1};
}
@netsi1964
netsi1964 / make_DR.DK_headlines_funny.js
Last active January 24, 2022 11:47
Reading (bad) news can be hard...
// Reading (bad) news can be hard.
// This script you should run in the console and then hover over headlines to get a new random headline.
// Simply copy it
// Open developer toolbar (press F12)
// In the "console" paste the script, press ENTER
// Enjoy! Simply hover over a headline to get a new random text :-)
// Try reading it seeing the photo together with the new random text
// THIS VERSION is for https://www.dr.dk
//
var HEADLINE_SELECTOR = '.dre-title-text, .dre-teaser-title__text, #dr-frontpage__top-spot #text'
@netsi1964
netsi1964 / scriptable_are_you_at_work.js
Created September 29, 2021 20:37
A script for scriptable which will give a notification about if you are at a location (work) or not
const workLocation = { longitude: 10.21377573, latitude: 56.15343598 }; // DOKK1
const currentLocation = await Location.current();
const distanceToWork = calcCrow(
currentLocation.latitude,
currentLocation.longitude,
workLocation.latitude,
workLocation.longitude
).toFixed(1);
const notification = new Notification();
@netsi1964
netsi1964 / html to svg.js
Created February 21, 2021 10:55
Takes a website and creates a SVG of it
Element.prototype.getDirectDesc = function () {
const descendants = Array.from(this.querySelectorAll("*"));
const directDescendants = descendants.filter(
(ele) =>
ele.parentElement === this &&
!["script", "iframe"].includes(ele.nodeName.toLowerCase())
);
return directDescendants;
};