Last active
May 7, 2022 21:14
-
-
Save koumaza/da81bec9312651d6f9b9ff2b8a014f2c to your computer and use it in GitHub Desktop.
Squarize everythings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SQ | |
// @namespace Violentmonkey Scripts | |
// @match *://*/* | |
// @grant none | |
// @version 1.0 | |
// @author koumaza | |
// ==/UserScript== | |
const sqz=(e)=>{ | |
e.style.setProperty('border-radius','0','important') | |
} | |
const replaceElemTag = (sourceElemParent, targetTag, beforeTag) => { | |
return sourceElemParent.innerHTML | |
.replace(`<${beforeTag}`,`<${targetTag}`) | |
.replace(`</${beforeTag}>`,`</${targetTag}>`) | |
} | |
const replaceElemTagByOuter = (sourceElem, targetTag, beforeTag) => { | |
return sourceElem.outerHTML | |
.replace(`<${beforeTag}`,`<${targetTag}`) | |
.replace(`</${beforeTag}>`,`</${targetTag}>`) | |
} | |
const replaceElemTagAll = (targetTag, beforeTag) => { | |
let elems = Array.apply([],document.getElementsByTagName(beforeTag)).map(b=>{return b.parentNode}) | |
elems.map(p=>{ | |
p.innerHTML = replaceElemTag(p,targetTag,beforeTag) | |
}) | |
} | |
const applyAllAttrs = (attrs, elem) => { | |
let e = elem | |
attrs.map(a=>e.setAttribute(a[0],a[1])) | |
return e | |
} | |
const sqzRect = (e) => { | |
e.removeAttribute('rx') | |
e.removeAttribute('ry') | |
e.style.setProperty('shape-rendering','crispEdges','important') | |
} | |
const chkNaN = n => {return !isNaN(Number(n)) ? Number(n) : ''} | |
const sqzCircle = (e) => { | |
let attrs = [...e.attributes].map(a=>[a.name,a.value]) | |
let a = applyAllAttrs(attrs,document.createElementNS('http://www.w3.org/2000/svg', 'rect')) | |
let r = chkNaN(e.getAttribute('r')) | |
let l = chkNaN(e.getAttribute('r')*2) | |
a.setAttribute('width',l) | |
a.setAttribute('height',l) | |
// a.setAttribute('rx','') | |
// a.setAttribute('ry','') | |
a.setAttribute('x',chkNaN(e.getAttribute('cx')-r)) | |
a.setAttribute('y',chkNaN(e.getAttribute('cy')-r)) | |
a.removeAttribute('cx') | |
a.removeAttribute('cy') | |
a.removeAttribute('r') | |
a.style.setProperty('shape-rendering','crispEdges','important') | |
a.constructor = SVGRectElement | |
e.parentNode.replaceChild(a, e) | |
} | |
const sqzEllipse = (e) => { | |
let attrs = [...e.attributes].map(a=>[a.name,a.value]) | |
let a = applyAllAttrs(attrs,document.createElementNS('http://www.w3.org/2000/svg', 'rect')) | |
a.setAttribute('width',chkNaN(e.getAttribute('rx')*2)) | |
a.setAttribute('height',chkNaN(e.getAttribute('ry')*2)) | |
// a.setAttribute('rx','') | |
// a.setAttribute('ry','') | |
a.setAttribute('x',chkNaN(e.getAttribute('cx')-e.getAttribute('rx'))) | |
a.setAttribute('y',chkNaN(e.getAttribute('cy')-e.getAttribute('ry'))) | |
a.removeAttribute('cx') | |
a.removeAttribute('cy') | |
a.removeAttribute('rx') | |
a.removeAttribute('ry') | |
a.style.setProperty('shape-rendering','crispEdges','important') | |
a.constructor = SVGRectElement | |
e.parentNode.replaceChild(a, e) | |
} | |
const doSqz = () => { | |
Array.apply([],document.getElementsByTagName('*')).map(e => { | |
sqz(e) | |
switch (e.tagName) { | |
case 'rect': sqzRect(e);break | |
case 'circle': sqzCircle(e);break | |
case 'ellipse': sqzEllipse(e);break | |
default: break | |
} | |
}) | |
// Array.apply([],document.getElementsByTagName('iframe')).map(i=>{ | |
// Array.apply([],i.contentWindow.document.getElementsByTagName('*')).map(e=>sqz(e)) | |
// }) | |
} | |
window.addEventListener('load', () => { | |
doSqz() | |
setInterval(() => { | |
doSqz() | |
}, 500) | |
}) | |
const s=document.createElement('style') | |
s.innerHTML=`*,:before,:after{border-radius:0!important;}` | |
document.head.appendChild(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment