Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name X/Twitter Quicksave
- // @version 1.0
- // @description Double-click on expanded images to save them with a useful filename
- // @author Anonymous
- // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
- // @match https://twitter.com/*
- // @exclude-match https://twitter.com/settings/*
- // @grant GM_download
- // @run-at document-end
- // ==/UserScript==
- (function() {
- function construct_quicksave()
- {
- var expandimgs = $("[role='dialog'] [aria-modal='true'][role='dialog'] [aria-label='Image'] img[alt]:not(.quicksave)");
- if(expandimgs.length)
- {
- $(expandimgs).each(function() {
- var iurl = this.src;
- this.addEventListener("dblclick", function(e) {
- let turl = location.href;
- let idata = iurl.match(/https?:\/\/pbs\.twimg\.com\/media\/([A-Za-z0-9_\-]+)\?/);
- let tdata = turl.match(/https?:\/\/twitter\.com\/([A-Za-z0-9_]+)\/status\/([0-9]+)\/photo\/([0-9])/);
- let srcname = iurl.replace(/format=(jpg|webp)/, "format=png");
- let newname = "twitter@" + tdata[1] + "#" + tdata[2] + "-" + tdata[3] + "_[" + idata[1] + "].png";
- GM_download({ "url": srcname, "name": newname });
- });
- this.classList.add("quicksave");
- });
- }
- }
- window.onload = function() {
- var bdy = document.querySelector("body");
- var cfg = { childList: true, subtree: true };
- var obs = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- construct_quicksave();
- });
- });
- obs.observe(bdy, cfg);
- construct_quicksave();
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment