// ==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.2 // @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,i,o,a){try{var s=e[o](a),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,i)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(i,o){var a=e.apply(t,r);function s(e){n(a,i,o,s,l,"next",e)}function l(e){n(a,i,o,s,l,"throw",e)}s(void 0)}))}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(){return(o=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],i=n[1],o=n[2],a=n[3];return e.h("label",{key:r},e.h("input",{checked:o,onInput:function(e){return a(e.target.checked)},type:"checkbox"}),e.h("span",null,i),e.h("br",null))}));return e.h("div",{className:x},n)},I=function(t){var n=t.className,r=t.site,i=t.title;return r.icon?e.h("img",{alt:r.title,className:n,src:r.icon,title:i}):null},Q="Sites_searchBar__1cpJl",R="Sites_searchInput__1iJDL",L="Sites_resultCount__2p4vG",E="Sites_siteList__1Y3wR",U="Sites_catList__6txMX",j="Sites_checked__3D9QY",O="Sites_title__1Gu_F",N="Sites_extraIcon__jwLPa",G="Sites_siteIcon__3uzGl";C(".Sites_searchBar__1cpJl{display:flex;flex-direction:row;margin-bottom:1em}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL{background-color:hsla(0,0%,100%,.9);border-radius:3px;border:1px solid #a6a6a6;box-shadow:inset 0 1px 0 rgba(0,0,0,.07);display:flex;flex-direction:row;height:24px;line-height:normal;outline:0;padding:3px 7px;transition:all .1s linear;width:100%}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL[focus-within]{background-color:#fff;border-color:#e77600;box-shadow:0 0 2px 2px rgba(228,121,17,.25)}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL:focus-within{background-color:#fff;border-color:#e77600;box-shadow:0 0 2px 2px rgba(228,121,17,.25)}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL>*{background-color:transparent;border:none;height:16px}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL>button{margin:0 0 0 .7em;padding:0}.Sites_searchBar__1cpJl .Sites_searchInput__1iJDL>input{flex-grow:1;outline:none;padding:0 0 0 .5em}.Sites_searchBar__1cpJl .Sites_resultCount__2p4vG{font-weight:700;margin-left:2em;min-width:140px;text-align:right}.Sites_searchBar__1cpJl .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 T=function(t){var n=t.q,r=t.setQ;return e.h("div",{className:R},e.h("span",null,"πŸ”"),e.h("input",{onInput:function(e){r(e.target.value.toLowerCase().trim())},placeholder:"Search",value:n}),e.h("button",{style:{display:n.length?"unset":"none"},title:"Clear",type:"button",onClick:function(){return r("")}},e.h(w,{type:"x"})))},M=function(t){var n=t.size,r="".concat(n,"px"),i={display:"inline-block",height:r,width:r};return e.h("div",{className:G,style:i})},D=function(t){var n=t.checked,r=t.setEnabled,i=t.site,o=e.h("input",{checked:n,onInput:function(e){return r((function(t){return e.target.checked?[].concat(A(t),[i.id]):t.filter((function(e){return e!==i.id}))}))},type:"checkbox"}),a=i.icon?e.h(I,{className:G,site:i,title:i.title}):e.h(M,{size:16}),s=e.h("span",{className:O,title:i.title},i.title),l=[i.noAccessMatcher?e.h(w,{className:N,title:"Access restricted",type:"lock"}):null,i.noResultsMatcher?e.h(w,{className:N,title:"Site supports fetching of results",type:"tick"}):null];return e.h("label",{className:n?j:null},o,a," ",s," ",l)},W=function(t){var n=t.enabled,r=t.name,i=t.setEnabled,o=t.sites,a=o.map((function(t){return e.h(D,{checked:n.includes(t.id),setEnabled:i,site:t})}));return e.h("div",{className:U},e.h("h4",null,r," ",e.h("span",null,"(",o.length,")")),a)},J=function(n){var r=n.enabledSites,i=n.setEnabledSites,o=n.sites,a=l(t.useState(""),2),s=a[0],A=a[1],c=Object.keys(g).map((function(e){var t=o.filter((function(t){return t.category===e}));return s.length?t.filter((function(e){return e.title.toLowerCase().includes(s)})):t})),u=Object.entries(g).map((function(t,n){var o=l(t,2),a=o[0],s=o[1];return c[n].length?e.h(W,{enabled:r,key:a,name:s,setEnabled:i,sites:c[n]}):null})),p=c.reduce((function(e,t){return e+t.length}),0);return e.h(e.Fragment,null,e.h("div",{className:Q},e.h(T,{q:s,setQ:A}),e.h("div",{className:L},"Showing ",e.h("span",null,p)," sites.")),e.h("div",{className:E},u))},P="About_about__3lHx7",H="About_top__3XyCB",V="About_content__1xMTu";C(".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",F="Config_top__2kgQ3",z="Config_link__3aqRB",q="Config_active__iBK3y",X="Config_body__2JuhF",$="Config_controls__3hBBQ";C('.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 ee=[["show_category_captions","Show category captions"],["open_blank","Open links in new tab"],["fetch_results","Automatically fetch results"]],te=function(n){var r=n.config,i=n.setConfig,o=n.setShow,a=n.show,s=n.sites,c=l(t.useState(r.enabled_sites),2),u=c[0],_=c[1],f=t.useState(r.show_category_captions),g=t.useState(r.open_blank),d=t.useState(r.fetch_results),m=l(f,2),b=m[0],S=m[1],y=l(g,2),v=y[0],k=y[1],C=l(d,2),x=C[0],I=C[1],Q=[f,g,d],R=ee.map((function(e,t){return[].concat(A(e),A(Q[t]))})),L=l(t.useState(0),2),E=L[0],U=L[1],j=[{title:"Sites",icon:"world",comp:e.h(J,{enabledSites:u,setEnabledSites:_,sites:s})},{title:"Options",icon:"cog",comp:e.h(B,{options:R})},{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:F},j.map((function(t,n){var r=t.title,i=t.icon;return e.h("button",{className:E===n?q:null,type:"button",onClick:function(){return U(n)}},e.h(w,{title:r,type:i})," ",r)})),e.h("div",{className:z},e.h("a",{target:"_blank",rel:"noreferrer",href:p},"πŸŽ₯ ",h))),e.h("div",{className:X},j.map((function(t,n){var r=t.comp;return e.h("div",{style:{display:E===n?"block":"none"}},r)}))),e.h("div",{className:$},e.h("div",null,e.h("button",{className:"btn primary small",onClick:function(){i({enabled_sites:u,fetch_results:x,open_blank:v,show_category_captions:b}),o(!1)},type:"button"},"OK"),e.h("button",{className:"btn small",onClick:function(){o(!1),_(r.enabled_sites),I(r.fetch_results),k(r.open_blank),S(r.show_category_captions)},type:"button"},"Cancel")))))},ne=function(e,t){var n=t.id,r=t.title,i=t.year,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.replace(new RegExp("{{IMDB_TITLE}}","g"),o?encodeURIComponent(r):r).replace(new RegExp("{{IMDB_ID}}","g"),n).replace(new RegExp("{{IMDB_YEAR}}","g"),i)},re=function(e,n){var r=l(t.useState(null),2),i=r[0],o=r[1];return t.useEffect((function(){var t;if(n.noResultsMatcher){var r=n.url,i={timeout:2e4,onload:function(e){return o(function(e,t){if(e.responseHeaders&&e.responseHeaders.includes("Refresh: 0; url="))return S;if(!e.responseText)return v;if(e.responseText.includes("The blog that you are about to view may contain content only suitable for adults."))return S;if(e.responseText.includes("Checking your browser before accessing"))return S;if(t.noAccessMatcher&&(Array.isArray(t.noAccessMatcher)?t.noAccessMatcher:[t.noAccessMatcher]).some((function(t){return e.responseText.includes(t)})))return S;if(Array.isArray(t.noResultsMatcher)){var n,r=l(t.noResultsMatcher,4),i=r[0],o=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!"),v}switch(i){case"EL_COUNT":var u;try{u=n.querySelectorAll(o)}catch(e){return console.error(e),v}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 ae=function(t){var n,r,i=t.imdbInfo,o=t.site;switch(re(i,o)){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 S: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 v:n="error",r="Error fetching results! (See dev console for details)";break;default:return null}return e.h(w,{className:oe,title:r,type:n})},se=function(){return e.h(e.Fragment,null,"Β ",e.h("span",{className:"ghost"},"|"))},le=function(n){var r=n.config,i=n.imdbInfo,a=n.last,s=n.site,A=r.open_blank?{target:"_blank",rel:"noreferrer"}:{},c=function(e,n,r){var i=t.useRef(),o=Array.isArray(e),a=o?"":ne(e,r,!1);return t.useEffect((function(){if(o){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=ne(s[e],r,!1),A.appendChild(t)})),document.body.appendChild(A),i.current=A}return function(){i.current&&i.current.remove()}})),[a,function(){o&&i.current&&(console.log("POST"),i.current.submit())}]}(s.url,r.open_blank,i),u=l(c,2),p=u[0],h=u[1];return e.h("span",{className:ie},e.h("a",o({href:p,onClick:h},A),e.h(I,{site:s}),e.h("span",null,s.title)),e.h(ae,{imdbInfo:i,site:s}),a?null:e.h(se,null))},Ae="LinkList_linkList__rlGOn",ce="LinkList_h4__2axTi";C(".LinkList_linkList__rlGOn{line-height:1.6rem}.LinkList_h4__2axTi{margin-top:.5rem}");var ue=function(t){var n=t.config,r=t.imdbInfo,i=t.sites;return Object.entries(g).map((function(t){var o=l(t,2),a=o[0],s=o[1],A=i.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:ce},s):null;return e.h(e.Fragment,null,c,e.h("div",{className:Ae},A.map((function(t,i){return e.h(le,{config:n,imdbInfo:r,last:i===A.length-1,site:t})}))))}))},pe="App_configWrapper__2KuAE";C(".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 he=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(_);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)}}(),_e=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(_,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,i=n.status,o=n.statusText;if(200===i)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(i," ").concat(o)))},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}(),de="legacy"===ge.layout?".titlereference-section-overview > *:last-child":".title-overview",me=document.querySelector(de);if(!me)throw new Error("LTA: Could not find target container!");var be=document.createElement("div");be.style.position="relative",be.classList.add("article"),me.appendChild(be),e.render(e.h((function(n){var r=n.imdbInfo,i=function(){var e=l(t.useState(),2),n=e[0],r=e[1];return t.useEffect((function(){he().then((function(e){return r(e)})).catch((function(){return r(f)}))}),[]),t.useEffect((function(){n&&_e(n)}),[n]),{config:n,setConfig:r}}(),o=i.config,a=i.setConfig,A=fe(),c=l(t.useState(!1),2),u=c[0],p=c[1];return t.useEffect((function(){o&&o.first_run&&(p(!0),a((function(e){return s(s({},e),{},{first_run:!1})})))}),[o]),o&&A.length?e.h(e.Fragment,null,"legacy"===r.layout?e.h("hr",null):null,e.h("div",{className:pe},e.h("button",{onClick:function(){return p((function(e){return!e}))},title:"Configure",type:"button"},e.h(w,{type:"cog"})),e.h(te,{config:o,setConfig:a,setShow:p,sites:A,show:u})),e.h(ue,{config:o,imdbInfo:r,sites:A})):null}),{imdbInfo:ge}),be)}(preact,preactHooks);