SpyMomiji

推特圖片自動 orig

Jul 28th, 2021
705
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         推特圖片自動 orig
  3. // @namespace    https://www.plurk.com/SpyMomiji
  4. // @version      1.0
  5. // @description  推特圖片自動 orig,請先將圖片另開啟新分頁才會有效
  6. // @author       SpyMomiji
  7. // @match        ^https://pbs.twimg.com/media/*
  8. // @grant        everyone who love kemomimi
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.     RegExp.prototype.if = function(i,a){
  14.         var s = this.exec(i);
  15.         if(s&&a) a.apply(null,s);
  16.         return Boolean(s);
  17.     };
  18.     /^https:\/\/pbs\.twimg\.com\/media\/(.*)/.if(location.href,function(_,path){
  19.         var letsgo = function(_,n,f,stop){
  20.             if(stop) return;
  21.             location.href = `https://pbs.twimg.com/media/${n}.${f}:orig`;
  22.         }
  23.         var query = path.indexOf('?');
  24.         if(query!=-1){
  25.             var fm,nm;
  26.             path.substr(query+1).split('&').forEach(function(qi){
  27.                 if(!/^format=(jpg|jpeg|png)$/.if(qi,function(_,f){fm = f;}))
  28.                     /^name=(orig)$/.if(qi,function(_,n){nm = n;})
  29.             })
  30.             if(fm) letsgo(null,path.substr(0,query),fm,nm);
  31.         }
  32.         else /^([A-Za-z0-9-_]*)\.(jpg|jpeg|png)(:orig)?/.if(path,letsgo);
  33.     });
  34. })();
RAW Paste Data