old-twitter-image-search/dist/otis.user.js

33 lines
51 KiB
JavaScript
Raw Permalink Normal View History

2023-07-13 08:28:59 +02:00
// ==UserScript==
// @name Old Twitter Image Search
// @namespace vite-plugin-monkey
// @version 1.1.5
2023-07-13 08:28:59 +02:00
// @author SoberOatmeal
// @description otis
// @license MIT
// @match https://twitter.com/*
// @connect donmai.us
// @connect saucenao.com
// @connect twimg.com
// @connect api.twitter.com
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.xmlHttpRequest
// @grant GM_addStyle
2023-07-13 08:28:59 +02:00
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @inject-into page
// @run-at document-start
2023-07-13 08:28:59 +02:00
// ==/UserScript==
(t=>{if(typeof GM_addStyle=="function"){GM_addStyle(t);return}const i=document.createElement("style");i.textContent=t,document.head.append(i)})(' .otis-icon{width:16px;vertical-align:middle;margin-right:20px;margin-left:6px;margin-bottom:4px}.otis-icon:hover{opacity:.8}.otis-icon-loading{opacity:.6!important;animation-name:icon-spin;animation-duration:2s;animation-iteration-count:infinite;animation-timing-function:linear}.otis-icon-noresult{opacity:.3!important}.otis-danbo-icon{width:18px;vertical-align:middle;margin-bottom:2px}.danbo-text-link{color:var(--light-gray);font-weight:700;font-size:12px}.danbo-more-results{margin-left:250px}.danbo-item>img,.danbo-item>div{vertical-align:middle;display:inline-block}.danbo-item>div{margin-left:10px}.danbo-artist-name{font-size:13px;bottom:3px;position:relative;font-weight:700;display:inline-block;cursor:pointer}.danbo-artist-name>a{color:var(--light-gray)}.danbo-artist-banned{color:#f91880!important;text-decoration:line-through}.danbo-artist-name>img:hover{opacity:.8}.danbo-artist-name-tweetpage{display:block;width:fit-content;bottom:unset}.tweet-time:after{color:var(--light-gray)!important;content:"\xB7";margin:0 3px}@keyframes icon-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}} ');
2023-07-13 08:28:59 +02:00
(function () {
2023-07-19 13:10:32 +02:00
'use strict';
2023-07-13 08:28:59 +02:00
const ye=(e,A)=>e===A,Te=Symbol("solid-track"),E={equals:ye};let xe=ue;const Y=1,k=2,re={owned:null,cleanups:null,context:null,owner:null};var b=null;let Q=null,m=null,z=null,X=null,F=0;function B(e,A){const t=m,n=b,s=e.length===0,o=A===void 0?n:A,l=s?re:{owned:null,cleanups:null,context:o?o.context:null,owner:o},i=s?e:()=>e(()=>U(()=>C(l)));b=l,m=null;try{return W(i,!0)}finally{m=t,b=n;}}function L(e,A){A=A?Object.assign({},E,A):E;const t={value:e,observers:null,observerSlots:null,comparator:A.equals||void 0},n=s=>(typeof s=="function"&&(s=s(t.value)),ae(t,s));return [le.bind(t),n]}function N(e,A,t){const n=fe(e,A,!1,Y);G(n);}function _(e,A,t){t=t?Object.assign({},E,t):E;const n=fe(e,A,!0,0);return n.observers=null,n.observerSlots=null,n.comparator=t.equals||void 0,G(n),le.bind(n)}function U(e){if(m===null)return e();const A=m;m=null;try{return e()}finally{m=A;}}function oe(e){return b===null||(b.cleanups===null?b.cleanups=[e]:b.cleanups.push(e)),e}function le(){if(this.sources&&this.state)if(this.state===Y)G(this);else {const e=z;z=null,W(()=>Z(this),!1),z=e;}if(m){const e=this.observers?this.observers.length:0;m.sources?(m.sources.push(this),m.sourceSlots.push(e)):(m.sources=[this],m.sourceSlots=[e]),this.observers?(this.observers.push(m),this.observerSlots.push(m.sources.length-1)):(this.observers=[m],this.observerSlots=[m.sources.length-1]);}return this.value}function ae(e,A,t){let n=e.value;return (!e.comparator||!e.comparator(n,A))&&(e.value=A,e.observers&&e.observers.length&&W(()=>{for(let s=0;s<e.observers.length;s+=1){const o=e.observers[s],l=Q&&Q.running;l&&Q.disposed.has(o),(l?!o.tState:!o.state)&&(o.pure?z.push(o):X.push(o),o.observers&&ve(o)),l||(o.state=Y);}if(z.length>1e6)throw z=[],new Error},!1)),A}function G(e){if(!e.fn)return;C(e);const A=F;Ve(e,e.value,A);}function Ve(e,A,t){let n;const s=b,o=m;m=b=e;try{n=e.fn(A);}catch(l){return e.pure&&(e.state=Y,e.owned&&e.owned.forEach(C),e.owned=null),e.updatedAt=t+1,de(l)}finally{m=o,b=s;}(!e.updatedAt||e.updatedAt<=t)&&(e.updatedAt!=null&&"observers"in e?ae(e,n):e.value=n,e.updatedAt=t);}function fe(e,A,t,n=Y,s){const o={fn:e,state:n,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:A,owner:b,context:b?b.context:null,pure:t};return b===null||b!==re&&(b.owned?b.owned.push(o):b.owned=[o]),o}function ce(e){if(e.state===0)return;if(e.state===k)return Z(e);if(e.suspense&&U(e.suspense.inFallback))return e.suspense.effects.push(e);const A=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<F);)e.state&&A.push(e);for(let t=A.length-1;t>=0;t--)if(e=A[t],e.state===Y)G(e);else if(e.state===k){const n=z;z=null,W(()=>Z(e,A[0]),!1),z=n;}}function W(e,A){if(z)return e();let t=!1;A||(z=[]),X?t=!0:X=[],F++;try{const n=e();return Se(t),n}catch(n){t||(X=null),z=null,de(n);}}function Se(e){if(z&&(ue(z),z=null),e)return;const A=X;X=null,A.length&&W(()=>xe(A),!1);}function ue(e){for(let A=0;A<e.length;A++)ce(e[A]);}function Z(e,A){e.state=0;for(let t=0;t<e.sources.length;t+=1){const n=e.sources[t];if(n.sources){const s=n.state;s===Y?n!==A&&(!n.updatedAt||n.updatedAt<F)&&ce(n):s===k&&Z(n,A);}}}function ve(e){for(let A=0;A<e.observers.length;A+=1){const t=e.observers[A];t.state||(t.state=k,t.pure?z.push(t):X.push(t),t.observers&&ve(t));}}function C(e){let A;if(e.sources)for(;e.sources.length;){const t=e.sources.pop(),n=e.sourceSlots.pop(),s=t.observers;if(s&&s.length){const o=s.pop(),l=t.observerSlots.pop();n<s.length&&(o.sourceSlots[l]=n,s[n]=o,t.observerSlots[n]=l);}}if(e.owned){for(A=e.owned.length-1;A>=0;A--)C(e.owned[A]);e.owned=null;}if(e.cleanups){for(A=e.cleanups.length-1;A>=0;A--)e.cleanups[A]();e.cleanups=null;}e.state=0;}function Ne(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function de(e,A=b){throw Ne(e)}const je=Symbol("fallback");function ne(e){for(let A=0;A<e.length;A++)e[A]();}function Le(e,A,t={}){let n=[],s=[],o=[],l=0,i=A.length>1?[]:null;return oe(()=>ne(o)),()=>{let f=e()||[],a,r;return f[Te],U(()=>{let d=f.length,u,v,P,V,x,p,g,y,w;if(d===0)l!==0&&(ne(o),o=[],n=[],s=[],l=0,i&&(i=[])),t.fallba
Go to Profile Menu > Settings to add it.`),[];const n=512,s=80,o="http://saucenao.com/search.php",l=new URL(o);l.searchParams.append("numres","5"),l.searchParams.append("output_type","2"),l.searchParams.append("dbmask",String(n)),l.searchParams.append("api_key",A),l.searchParams.append("url",e);const f=await new Promise((c,d)=>{K({url:l.toString(),method:"GET",responseType:"json",anonymous:!0,onload:u=>c(u.responseText),onerror:u=>d(u)});});return JSON.parse(f).results.filter(c=>Number(c.header.similarity)>=s).map(c=>{const d=c.data,u=c.header.thumbnail,v=new URL(d.source).hostname;return {id:d.danbooru_id,timestamp:"",source_domain:v,thumbnail:u,img_width:-1,img_height:-1}})}async function Je(e){const A=`${D}/artists.json`,t=`https://twitter.com/${e}`,n=new URL(A);n.searchParams.append("search[url_matches]",t),n.searchParams.append("only","id,name,urls,is_banned");const o=await new Promise((f,a)=>{K({url:n.toString(),method:"GET",responseType:"json",anonymous:!0,onload:r=>f(r.responseText),onerror:r=>a(r)});});let i=JSON.parse(o).shift();return i&&(i.urls=i.urls.filter(f=>f.is_active&&!(f.url.includes("twitter.com/intent/")||f.url.includes("pixiv.net/stacc/")))),i}const qe="data:image/x-icon;base64,AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1PEb/t8nc/8vi/v+cwPv/XXKU/z5off9nyv7/P6H5/ylPcf82gr3/VLv7/ypjl/8PDxH/Ro2u/2X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N/9rT1f+nw/D/jbPy/8nS4/+mw/b/co/F/1pxnP94nuL/hK75/4Ww+f95oOH/bZHO/3uo8f97qvn/eKf5/3al+P97p/j/ibD5/5m6+v+nw/v/sMn8/7rS/P+wye3/nLfT/6/F3f89RFT/TlNu/01RbP9MUWz/T1Nx/09VdP8wN0X/LztL/zE+T/8xQFL/MUBU/zU9U/9XXon/TFJ3/zI2TP8jKjj/ISw5/y42TP8UFh7/BwcH/z86Of82Nj3/ESpB/wZRe/8TQFz/XWyC/83W7v+euez/gKj4/3+n+P95oOz/gar4/4Sv+f+Hsvr/h7P6/2yOxv9xltL/krr7/6HE+/+pyPz/ocD6/7HK+/+1zPv/pb/x/5m36v+IrOb/f6jo/4Ww8/9TV3P/U1d0/1FVcv9QVHH/S1Br/y41Qf8uOEX/Okpg/zdIXf8/Um3/WGON/3B5sf9HTG3/KzBC/yAoNf8sMkb/Pkts/0BScv8ODxL/DA0Q/9/g4f8mM0P/BzVX/xSLw/9Mwe7/JFBr/8zX5/+zy/n/rcX7/6rD+/+ow/v/qMT7/6jH+/+myPv/l777/4ez+v96oeH/Z4e8/4Ww+f+Crfj/f6j4/67J+/+2zfv/ts37
`;var vA=h("<a target=_blank>"),dA=h("<div class=dropdown-menu>"),PA=h('<span class="danbo-artist-name tweet-button">'),mA=h("<a target=_blank> <!> ");const bA=pe;function hA({username:e,user_id:A,is_tweet_page:t}){let n;const[s,o]=L(),[l,i]=L(!1),f=async a=>{const r=n;r.classList.add("otis-icon-loading"),r.classList.remove("otis-icon-noresult");const c=await Je(e);if(r.classList.remove("otis-icon-loading"),!c){r.classList.add("otis-icon-noresult"),r.title="No artist tag found on Danbooru";return}o(c),c.urls.length>=1&&i(!0);};return (()=>{var a=PA();return a.$$click=f,a.classList.toggle("danbo-artist-name-tweetpage",!!t),S(a,T(he,{ref(r){var c=n;typeof c=="function"?c(r):n=r;},title:"Perform manual artist search on Danbooru"}),null),S(a,T(me,{get when(){return s()},fallback:t?"Artist Search":"",get children(){return [(()=>{var r=vA();return r.$$mouseover=()=>i(!0),S(r,()=>s().name),N(c=>{var d=s().is_banned?`${D}/artists/${s().id}`:`${D}/posts?tags=${s().name}`,u=!!s().is_banned;return d!==c.e&&j(r,"href",c.e=d),u!==c.t&&r.classList.toggle("danbo-artist-banned",c.t=u),c},{e:void 0,t:void 0}),r})(),(()=>{var r=dA();return ee(bA,r,()=>()=>i(!1)),r.addEventListener("mouseleave",()=>i(!1)),S(r,T(Pe,{get each(){return s().urls},children:({url:c})=>(()=>{var d=mA(),u=d.firstChild,v=u.nextSibling;return v.nextSibling,j(d,"href",c),S(d,c,v),d})()})),N(()=>r.hidden=!l()),r})()]}}),null),a})()}async function pA(){if(document.URL.endsWith("/old/settings"))return Ie();const A=(o,l)=>{for(const i of o){if(i.type!=="childList")return;i.addedNodes.forEach(f=>{const a=f,r=a.getElementsByClassName("tweet-media").item(0);if(!r)return;const c=r.getElementsByTagName("img");if(!c||r.getElementsByTagName("video").length)return;const u=a.getElementsByClassName("tweet-interact").item(0),v=a.getElementsByClassName("tweet-avatar-link").item(0),P=u==null?void 0:u.getElementsByClassName("tweet-interact-more").item(0),V=a.getElementsByClassName("tweet-time").item(0),x=a.getElementsByClassName("tweet-body-main").item(0),p=a.dataset.tweetId||"0",g=v.href.split("/").pop()||"*";let y=[];for(const M of c)y.push(M.src);const w=()=>T(cA,{media_url:y,id:p,username:g}),O=()=>T(hA,{username:g,user_id:p,get is_tweet_page(){return !!x}});x?x==null||x.prepend(O()):V==null||V.after(O()),P==null||P.before(...w());});}},t=new MutationObserver(A),n=document.getElementById("timeline");if(!n)return;const s={subtree:!1,childList:!0,attributes:!1};t.observe(n,s);}const ze=async(e=0)=>e>=5?void 0:document.getElementById("center-cell")?(Oe(uA),pA()):(await iA(1e3),ze(e+=1));ze();J(["click","mouseover"]);
2023-07-13 08:28:59 +02:00
})();