Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Last active April 14, 2021 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dieseltravis/3eabc5a10aad42dc80d99502f07ae23e to your computer and use it in GitHub Desktop.
Save dieseltravis/3eabc5a10aad42dc80d99502f07ae23e to your computer and use it in GitHub Desktop.
rotate all the post images on mltshp clockwise

Bookmarklet: 🔃

<!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>
// 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);
});
[...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