Bookmarklet: 🔃
Last active
April 14, 2021 05:34
-
-
Save dieseltravis/3eabc5a10aad42dc80d99502f07ae23e to your computer and use it in GitHub Desktop.
rotate all the post images on mltshp clockwise
This file contains 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
<!doctype html> | |
<html><body> | |
<a href='javascript:[...document.querySelectorAll(".the-image img")].forEach(img=>img.setAttribute("style",(img.getAttribute("style")||"").replace(/transform:rotate\((\d+\.?\d*)turn\)/,(m,p1)=>"transform:rotate("+(+p1+0.25)+"turn)")||"transform:rotate(0.25turn)"));'>🔃</a> | |
</body></html> |
This file contains 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
// get all of the post images | |
let imgNodes = document.querySelectorAll(".the-image img"); | |
// convert the nodelist to an array | |
let imgArray = [...imgNodes]; | |
imgArray.forEach(img => { | |
// default to empty string if null | |
let oldStyle = img.getAttribute("style") || ""; | |
// use a regex to match the rotation css | |
let newStyle = oldStyle.replace(/transform:rotate\((\d+\.?\d*)turn\)/, (m, p1) => { | |
// add a quarter-turn | |
return "transform:rotate(" + (+p1 + 0.25) + "turn)"; | |
}); | |
// default to first clock-wise turn if empty | |
let newStyle = newStyle || "transform:rotate(0.25turn)"; | |
img.setAttribute("style", newStyle); | |
}); |
This file contains 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
[...document.querySelectorAll(".the-image img")].forEach(img=>img.setAttribute("style",(img.getAttribute("style")||"").replace(/transform:rotate\((\d+\.?\d*)turn\)/,(m,p1)=>"transform:rotate("+(+p1+0.25)+"turn)")||"transform:rotate(0.25turn)")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment