// ==UserScript== // @name IMDb: Link 'em all! // @description Adds all kinds of links to IMDb, customizable! // @namespace https://greasyfork.org/en/users/8981-buzz // @match *://*.imdb.com/title/tt*/* // @connect * // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js // @require https://unpkg.com/preact@10.4.5/dist/preact.umd.js // @require https://unpkg.com/preact@10.4.5/hooks/dist/hooks.umd.js // @license GPLv2 // @noframes // @author buzz // @version 2.0.1 // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM.getValue // @grant GM.setValue // @grant GM.xmlHttpRequest // @downloadURL none // ==/UserScript== !function(e,t){"use strict";function n(e,t,n,r,o,i,a){try{var s=e[i](a),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,o)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var a=e.apply(t,r);function s(e){n(a,o,i,s,l,"next",e)}function l(e){n(a,o,i,s,l,"throw",e)}s(void 0)}))}}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(){return(i=Object.assign||function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=new Array(t);nlabel>span{margin-left:10px}");var B=function(t){var n=t.options.map((function(t){var n=l(t,4),r=n[0],o=n[1],i=n[2],a=n[3];return e.h("label",{key:r},e.h("input",{checked:i,onInput:function(e){return a(e.target.checked)},type:"checkbox"}),e.h("span",null,o),e.h("br",null))}));return e.h("div",{className:x},n)},Q=function(t){var n=t.className,r=t.site,o=t.title;return r.icon?e.h("img",{alt:r.title,className:n,src:r.icon,title:o}):null},R="Sites_searchInput__1iJDL",I="Sites_resultCount__2p4vG",L="Sites_siteList__1Y3wR",E="Sites_catList__6txMX",U="Sites_checked__3D9QY",j="Sites_title__1Gu_F",O="Sites_extraIcon__jwLPa",G="Sites_siteIcon__3uzGl";w(".Sites_searchInput__1iJDL{background-color:hsla(0,0%,100%,.9);height:24px;line-height:normal;padding:3px 7px;width:100%;border-radius:3px;border:1px solid #a6a6a6;border-top-color:#949494;box-shadow:inset 0 1px 0 rgba(0,0,0,.07);outline:0;transition:all .1s linear}.Sites_searchInput__1iJDL:focus{background-color:#fff;border-color:#e77600;box-shadow:0 0 2px 2px rgba(228,121,17,.25)}.Sites_resultCount__2p4vG{font-weight:700;margin-bottom:8px}.Sites_resultCount__2p4vG>span{color:#000}.Sites_siteList__1Y3wR .Sites_catList__6txMX{display:flex;flex-wrap:wrap}.Sites_siteList__1Y3wR .Sites_catList__6txMX h4{width:100%}.Sites_siteList__1Y3wR .Sites_catList__6txMX label{align-items:center;color:#444;display:flex;flex-flow:row;padding:0 6px;transition:color .1s;width:25%}.Sites_siteList__1Y3wR .Sites_catList__6txMX label:hover{color:#222}.Sites_siteList__1Y3wR .Sites_catList__6txMX label.Sites_checked__3D9QY span{color:#000}.Sites_siteList__1Y3wR .Sites_catList__6txMX label .Sites_title__1Gu_F{flex-grow:1;overflow:hidden;text-overflow:ellipsis}.Sites_siteList__1Y3wR .Sites_catList__6txMX label input{margin-right:4px}.Sites_siteList__1Y3wR .Sites_catList__6txMX label .Sites_extraIcon__jwLPa{height:12px;margin-left:4px;width:12px}.Sites_siteList__1Y3wR .Sites_catList__6txMX label .Sites_siteIcon__3uzGl{flex-shrink:0;margin-right:6px}");var N=function(t){var n=t.q,r=t.setQ;return e.h("input",{className:R,onInput:function(e){r(e.target.value.toLowerCase().trim())},placeholder:"Search",value:n})},T=function(t){var n=t.size,r="".concat(n,"px"),o={display:"inline-block",height:r,width:r};return e.h("div",{className:G,style:o})},M=function(t){var n=t.checked,r=t.setEnabled,o=t.site,i=e.h("input",{checked:n,onInput:function(e){return r((function(t){return e.target.checked?[].concat(A(t),[o.id]):t.filter((function(e){return e!==o.id}))}))},type:"checkbox"}),a=o.icon?e.h(Q,{className:G,site:o,title:o.title}):e.h(T,{size:16}),s=e.h("span",{className:j,title:o.title},o.title),l=[o.noAccessMatcher?e.h(C,{className:O,title:"Site is access-restricted.",type:"lock"}):null,o.noResultsMatcher?e.h(C,{className:O,title:"Site allows fetching of results.",type:"tick"}):null];return e.h("label",{className:n?U:null},i,a," ",s," ",l)},D=function(t){var n=t.enabled,r=t.name,o=t.setEnabled,i=t.sites,a=i.map((function(t){return e.h(M,{checked:n.includes(t.id),setEnabled:o,site:t})}));return e.h("div",{className:E},e.h("h4",null,r," ",e.h("span",null,"(",i.length,")")),a)},W=function(n){var r=n.enabledSites,o=n.setEnabledSites,i=n.sites,a=l(t.useState(""),2),s=a[0],A=a[1],c=Object.keys(_).map((function(e){var t=i.filter((function(t){return t.category===e}));return s.length?t.filter((function(e){return e.title.toLowerCase().includes(s)})):t})),u=Object.entries(_).map((function(t,n){var i=l(t,2),a=i[0],s=i[1];return c[n].length?e.h(D,{enabled:r,key:a,name:s,setEnabled:o,sites:c[n]}):null})),p=c.reduce((function(e,t){return e+t.length}),0);return e.h(e.Fragment,null,e.h(N,{q:s,setQ:A}),e.h("div",{className:I},"Showing ",e.h("span",null,p)," sites."),e.h("div",{className:L},u))},P="About_about__3lHx7",H="About_top__3XyCB",V="About_content__1xMTu";w(".About_about__3lHx7{padding:1em 0;position:relative}.About_about__3lHx7 ul>li{margin-bottom:0}.About_about__3lHx7 h2{font-size:20px;margin:.5em 0}.About_about__3lHx7>:last-child{margin-bottom:0}.About_about__3lHx7 .About_top__3XyCB{text-align:center}.About_about__3lHx7 .About_content__1xMTu{width:61.8%;margin:0 auto}");var Y=function(){return e.h("div",{className:P},e.h("div",{className:H},e.h("h3",null,"🎥 ",h),e.h("p",null,"Adds all kinds of links to IMDb, customizable!")),e.h("div",{className:V},e.h("h2",null,"🔗 Links"),e.h("ul",null,e.h("li",null,e.h("a",{target:"_blank",rel:"noreferrer",href:p},"GitHub")),e.h("li",null,e.h("a",{target:"_blank",rel:"noreferrer",href:"https://greasyfork.org/scripts/17154-imdb-link-em-all"},"Greasy Fork"))),e.h("h2",null,"✨ Contributions"),e.h("p",null,"Add new sites or update existing entries."),e.h("ul",null,e.h("li",null,e.h("a",{target:"_blank",rel:"noreferrer",href:"https://github.com/buzz/imdb-link-em-all/issues/new"},"Open a GitHub issue")," ","or"),e.h("li",null,e.h("a",{target:"_blank",rel:"noreferrer",href:"https://greasyfork.org/en/scripts/17154-imdb-link-em-all/feedback"},"Give feedback")," ","on Greasy Fork.")),e.h("p",null,e.h("em",null,"Thanks to all the contributors!")," 👍"),e.h("h2",null,"⚖ License"),e.h("p",null,"This script is licensed under the terms of the"," ",e.h("a",{target:"_blank",rel:"noreferrer",href:"https://github.com/buzz/imdb-link-em-all/blob/master/LICENSE"},"GPL-2.0 License"),".")))},K="Config_popover__3RK3L",Z="Config_inner__2Sbjz",J="Config_top__2kgQ3",F="Config_link__3aqRB",z="Config_active__iBK3y",q="Config_body__2JuhF",X="Config_controls__3hBBQ";w('.Config_popover__3RK3L{background-color:#a5a5a5;border-radius:4px;box-shadow:0 0 2em rgba(0,0,0,.1);color:#333;display:block;font-family:Verdana,Arial,sans-serif;font-size:11px;left:-550px;line-height:1.5rem;padding:10px;position:absolute;top:28px;white-space:nowrap;width:800px;z-index:100}.Config_popover__3RK3L:before{border:8px solid transparent;border-bottom-color:#a5a5a5;content:"";display:block;height:8px;right:234px;position:absolute;top:-16px;width:0}.Config_popover__3RK3L .Config_inner__2Sbjz{display:flex;flex-direction:column;text-shadow:0 1px 0 hsla(0,0%,100%,.2)}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3{display:flex;flex-direction:row}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3 .Config_link__3aqRB{flex-grow:1;text-align:right}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3 .Config_link__3aqRB>a{color:#333;margin-left:12px;margin-right:4px}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3 .Config_link__3aqRB>a:visited{color:#333}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3>button{background-color:rgba(0,0,0,.05);border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:2px;border-top-right-radius:2px;border:1px solid rgba(0,0,0,.25);border-bottom:transparent;color:#424242;font-size:12px;margin:0 6px 0 0;outline:none;padding:0 6px;transform:translateY(1px);text-shadow:0 1px 0 hsla(0,0%,100%,.2)}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3>button:hover{background-color:rgba(0,0,0,.1);color:#222}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3>button.Config_active__iBK3y{background-color:#c2c2c2;color:#222}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3>button:last-child{margin-right:0}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_top__2kgQ3>button>img{vertical-align:text-bottom}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_body__2JuhF{background-color:#c2c2c2;border-bottom-left-radius:2px;border-bottom-right-radius:2px;border-top-right-radius:2px;border:1px solid rgba(0,0,0,.25);padding:12px 10px}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_body__2JuhF>div{overflow:hidden}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_body__2JuhF>div>:first-child{margin-top:0}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_body__2JuhF>div>:last-child{margin-bottom:0}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_controls__3hBBQ{display:flex;flex-direction:row;margin-top:10px}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_controls__3hBBQ>div:first-child{flex-grow:1}.Config_popover__3RK3L .Config_inner__2Sbjz .Config_controls__3hBBQ button{padding-bottom:0;padding-top:0;margin-right:12px}');var $=[["show_category_captions","Show category captions"],["open_blank","Open links in new tab"],["fetch_results","Automatically fetch results"]],ee=function(n){var r=n.config,o=n.setConfig,i=n.setShow,a=n.show,s=n.sites,c=l(t.useState(r.enabled_sites),2),u=c[0],f=c[1],g=t.useState(r.show_category_captions),_=t.useState(r.open_blank),d=t.useState(r.fetch_results),m=l(g,2),b=m[0],v=m[1],y=l(_,2),S=y[0],k=y[1],w=l(d,2),x=w[0],Q=w[1],R=[g,_,d],I=$.map((function(e,t){return[].concat(A(e),A(R[t]))})),L=l(t.useState(0),2),E=L[0],U=L[1],j=[{title:"Sites",icon:"world",comp:e.h(W,{enabledSites:u,setEnabledSites:f,sites:s})},{title:"Options",icon:"cog",comp:e.h(B,{options:I})},{title:"About",icon:"info",comp:e.h(Y,null)}];return e.h("div",{className:K,style:{display:a?"block":"none"}},e.h("div",{className:Z},e.h("div",{className:J},j.map((function(t,n){var r=t.title,o=t.icon;return e.h("button",{className:E===n?z:null,type:"button",onClick:function(){return U(n)}},e.h(C,{title:r,type:o})," ",r)})),e.h("div",{className:F},e.h("a",{target:"_blank",rel:"noreferrer",href:p},"🎥 ",h))),e.h("div",{className:q},j.map((function(t,n){var r=t.comp;return e.h("div",{style:{display:E===n?"block":"none"}},r)}))),e.h("div",{className:X},e.h("div",null,e.h("button",{className:"btn primary small",onClick:function(){o({enabled_sites:u,fetch_results:x,open_blank:S,show_category_captions:b}),i(!1)},type:"button"},"OK"),e.h("button",{className:"btn small",onClick:function(){i(!1),f(r.enabled_sites),Q(r.fetch_results),k(r.open_blank),v(r.show_category_captions)},type:"button"},"Cancel")))))},te=function(e,t){var n=t.id,r=t.title,o=t.year,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.replace(new RegExp("{{IMDB_TITLE}}","g"),i?encodeURIComponent(r):r).replace(new RegExp("{{IMDB_ID}}","g"),n).replace(new RegExp("{{IMDB_YEAR}}","g"),o)},ne=function(e,n){var r=l(t.useState(null),2),o=r[0],i=r[1];return t.useEffect((function(){var t;if(n.noResultsMatcher){var r=n.url,o={timeout:2e4,onload:function(e){return i(function(e,t){if(e.responseHeaders&&e.responseHeaders.includes("Refresh: 0; url="))return v;if(!e.responseText)return S;if(e.responseText.includes("The blog that you are about to view may contain content only suitable for adults."))return v;if(e.responseText.includes("Checking your browser before accessing"))return v;if(t.noAccessMatcher&&(Array.isArray(t.noAccessMatcher)?t.noAccessMatcher:[t.noAccessMatcher]).some((function(t){return e.responseText.includes(t)})))return v;if(Array.isArray(t.noResultsMatcher)){var n,r=l(t.noResultsMatcher,4),o=r[0],i=r[1],a=r[2],s=r[3],A=e.responseHeaders.match(/content-type:\s([^\s;]+)/),c=A?A[1]:"text/html";try{n=(new DOMParser).parseFromString(e.responseText,c)}catch(e){return console.error("Could not parse document!"),S}switch(o){case"EL_COUNT":var u;try{u=n.querySelectorAll(i)}catch(e){return console.error(e),S}if("GT"===a&&u.length>s)return b;if("LT"===a&&u.lengthimg{height:16px;width:16px;margin-right:4px}.SiteLink_linkWrapper__2uDyT .SiteLink_resultsIcon__3_V-k{margin-left:4px}");var ie=function(t){var n,r,o=t.imdbInfo,i=t.site;switch(ne(o,i)){case d:n="spinner",r="Loading…";break;case m:n="x",r="No Results found!";break;case b:n="tick",r="Results found!";break;case v:n="lock",r="You have to login to this site!";break;case y:n="timeout",r="You have to login to this site!";break;case S:n="error",r="Error fetching results! (See dev console for details)";break;default:return null}return e.h(C,{className:oe,title:r,type:n})},ae=function(){return e.h(e.Fragment,null," ",e.h("span",{className:"ghost"},"|"))},se=function(n){var r=n.config,o=n.imdbInfo,a=n.last,s=n.site,A=r.open_blank?{target:"_blank",rel:"noreferrer"}:{},c=function(e,n,r){var o=t.useRef(),i=Array.isArray(e),a=i?"":te(e,r,!1);return t.useEffect((function(){if(i){var t=l(e,2),a=t[0],s=t[1],A=document.createElement("form");A.action=a,A.method="POST",A.style.display="none",A.target=n?"_blank":"_self",Object.keys(s).forEach((function(e){var t=document.createElement("input");t.type="text",t.name=e,t.value=te(s[e],r,!1),A.appendChild(t)})),document.body.appendChild(A),o.current=A}return function(){o.current&&o.current.remove()}})),[a,function(){i&&o.current&&(console.log("POST"),o.current.submit())}]}(s.url,r.open_blank,o),u=l(c,2),p=u[0],h=u[1];return e.h("span",{className:re},e.h("a",i({href:p,onClick:h},A),e.h(Q,{site:s}),e.h("span",null,s.title)),e.h(ie,{imdbInfo:o,site:s}),a?null:e.h(ae,null))},le="LinkList_linkList__rlGOn",Ae="LinkList_h4__2axTi";w(".LinkList_linkList__rlGOn{line-height:1.6rem}.LinkList_h4__2axTi{margin-top:.5rem}");var ce=function(t){var n=t.config,r=t.imdbInfo,o=t.sites;return Object.entries(_).map((function(t){var i=l(t,2),a=i[0],s=i[1],A=o.filter((function(e){return e.category===a&&n.enabled_sites.includes(e.id)}));if(!A.length)return null;var c=n.show_category_captions?e.h("h4",{className:Ae},s):null;return e.h(e.Fragment,null,c,e.h("div",{className:le},A.map((function(t,o){return e.h(se,{config:n,imdbInfo:r,last:o===A.length-1,site:t})}))))}))},ue="App_configWrapper__2KuAE";w(".App_configWrapper__2KuAE{position:absolute;right:20px;top:20px}.App_configWrapper__2KuAE>button{background:transparent;border:none;outline:none;padding:0}.App_configWrapper__2KuAE>button>img{vertical-align:baseline}");var pe=function(){var e=r(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=JSON,e.next=3,GM.getValue(f);case 3:return e.t1=e.sent,e.abrupt("return",e.t0.parse.call(e.t0,e.t1));case 5:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),he=function(){var e=r(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",GM.setValue(f,JSON.stringify(t)));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),fe=function(){var e=l(t.useState([]),2),n=e[0],r=e[1];return t.useEffect((function(){new Promise((function(e,t){return GM.xmlHttpRequest({method:"GET",url:"https://raw.githubusercontent.com/buzz/imdb-link-em-all/master/sites.json",nocache:!0,onload:function(n){var r=n.response,o=n.status,i=n.statusText;if(200===o)try{e(JSON.parse(r).sort((function(e,t){return e.title.localeCompare(t.title)})))}catch(e){t(e)}else t(new Error("Could not load sites: ".concat(o," ").concat(i)))},onerror:function(e){var n=e.status,r=e.statusText;t(new Error("Could not load sites: ".concat(n," ").concat(r)))}})})).then((function(e){return r(e)}))}),[]),n},ge=function(){var e=/^\/title\/tt([0-9]{7,8})\/([a-z]*)/.exec(window.location.pathname);if(!e)throw new Error("Could not parse IMDb URL!");var t={id:e[1],layout:["reference","combined"].includes(e[2])?"legacy":"new"},n="legacy"===t.layout?"h3[itemprop=name]":"h1";t.title=document.querySelector(n).innerText.trim();var r=/^(.+)\s+\((\d+)\)/.exec(t.title);return r&&(t.title=r[1].trim(),t.year=parseInt(r[2].trim(),10)),t}(),_e="legacy"===ge.layout?".titlereference-section-overview > *:last-child":".title-overview",de=document.querySelector(_e);if(!de)throw new Error("LTA: Could not find target container!");var me=document.createElement("div");me.style.position="relative",me.classList.add("article"),de.appendChild(me),e.render(e.h((function(n){var r=n.imdbInfo,o=function(){var e=l(t.useState(),2),n=e[0],r=e[1];return t.useEffect((function(){pe().then((function(e){return r(e)})).catch((function(){return r(g)}))}),[]),t.useEffect((function(){n&&he(n)}),[n]),{config:n,setConfig:r}}(),i=o.config,a=o.setConfig,A=fe(),c=l(t.useState(!1),2),u=c[0],p=c[1];return t.useEffect((function(){i&&i.first_run&&(p(!0),a((function(e){return s(s({},e),{},{first_run:!1})})))}),[i]),i&&A.length?e.h(e.Fragment,null,"legacy"===r.layout?e.h("hr",null):null,e.h("div",{className:ue},e.h("button",{onClick:function(){return p((function(e){return!e}))},title:"Configure",type:"button"},e.h(C,{type:"cog"})),e.h(ee,{config:i,setConfig:a,setShow:p,sites:A,show:u})),e.h(ce,{config:i,imdbInfo:r,sites:A})):null}),{imdbInfo:ge}),me)}(preact,preactHooks);