notes/.config/BraveSoftware/Brave-Browser/Greaselion/Temp/scoped_dirvcmAjP/vimeoBase.bundle.js

1 line
No EOL
4.4 KiB
JavaScript

(()=>{"use strict";const e="mnojpmjdmbbfmejpflffifhffcmidifd";let t=null;const r=()=>t,n=(e,t)=>e&&t?`${e}_${t}`:"",o=(e,t)=>`${e}#channel:${t}`,i=(e,t,r)=>{if(e.length<t.length)return"";const n=e.indexOf(t);if(-1===n)return"";const o=n+t.length,i=e.indexOf(r,o);let a="";return i!==o?a=-1!==i&&i>o||-1!==i?e.substring(o,i):e.substring(o):""===r&&(a=e.substring(o)),a},a=()=>"complete"===document.readyState&&"visible"===document.visibilityState,s=(e,t)=>`${e}: ${t.statusText} (${t.status})`,c=(RegExp(/&(?:amp|lt|gt|quot|#(0+)?39);/g.source),"vimeo"),l=e=>{if(!e)return"";const t=i(e,'"display_name":"','"');if(!t)return"";let r=null;try{r=JSON.parse(`{"brave_publisher":"${t}"}`)}catch(e){throw new Error(`Error parsing publisher name from video page: ${e}`)}return r.brave_publisher},u=e=>{if(!e)return"";let t=i(e,'<meta property="al:ios:url" content="vimeo://app.vimeo.com/users/','"');return t||(t=i(e,'<meta property="al:android:url" content="vimeo://app.vimeo.com/users/','"'),t||i(e,'<link rel="canonical" href="/','"'))},h=async()=>{const e=location.href,t=await fetch(e);if(!t.ok){const e=s("Publisher request failed",t);throw new Error(e)}const r=await t.text();if(!r)throw new Error("Publisher response empty");let a="",h="",m=u(r);if(m)a=(e=>e?l(e)||i(e,'<meta property="og:title" content="','"'):"")(r),a||(a=m);else{if(a=l(r),!a)throw new Error("Invalid publisher name");if(m=(e=>e?i(e,'"creator_id":',","):"")(r),!m)throw new Error("Invalid user id");const e=(e=>e?i(e,'<link rel="canonical" href="https://vimeo.com/','"'):"")(r);if(!e)throw new Error("Invalid video id")}return h=n(c,m),{url:e,publisherKey:o(c,m),publisherName:a,mediaKey:h,favIconUrl:""}},m=()=>{(e=>{if(!e)return!1;const t=["/","/about","/blog","/enterprise","/help","/jobs","/live","/log_in","/ondemand","/ott","/purchases","/search","/settings","/site_map","/stats","/stock","/upgrade","/upload","/videoschool","/watch","/watchlater"];if(t.includes(e)||t.includes(e+"/"))return!0;if(e.startsWith("/channels/staffpicks/"))return!1;const r=["/blog/","/categories/","/channels/","/features/","/help/","/manage/","/ott/","/settings/","/solutions/","/stock/"];for(const t of r)if(e.startsWith(t))return!0;return!1})(new URL(location.href).pathname)?(()=>{const e=r();e&&e.postMessage({type:"SavePublisherVisit",mediaType:"",data:{url:"https://vimeo.com",publisherKey:"vimeo.com",publisherName:"vimeo.com",favIconUrl:""}})})():p().then((e=>{const t=r();if(!t)throw new Error("Invalid port");t.postMessage({type:"SavePublisherVisit",mediaType:c,data:{url:e.url,publisherKey:e.publisherKey,publisherName:e.publisherName,mediaKey:e.mediaKey,favIconUrl:e.favIconUrl}})})).catch((e=>{throw new Error(`Failed to retrieve publisher data: ${e}`)}))},p=async()=>{return(e=location.pathname)&&/^\/\d+$/.test(e)?(async()=>{const e=location.href,t=encodeURI(e),r=await fetch(`https://vimeo.com/api/oembed.json?url=${t}`);if(!r.ok)return h();const i=await r.json();if(!i)return h();const a=i.author_url;if(!a)return h();const l=i.author_name;if(!l)throw new Error("Invalid publisher name");const m=i.video_id;if(!m||0===m)return h();const p=await fetch(a);if(!p.ok){const e=s("Publisher request failed",p);throw new Error(e)}const d=await p.text(),f=u(d);if(!f)throw new Error("Invalid user id");const b=o(c,f),v=n(c,m.toString());if(!v)throw new Error("Invalid media key");const w=(e=>e?`https://i.vimeocdn.com/portrait/${e}_300x300.webp`:"")(f);return{url:a,publisherKey:b,publisherName:l,mediaKey:v,favIconUrl:w}})():h();var e};let d=!1,f="";const b=e=>{e&&(e.url||"complete"===e.status)&&location.href!==f&&(f=location.href,m())};var v;chrome.extension.inIncognitoContext||(v=e=>{e?(a()?m():document.addEventListener("readystatechange",(function(){a()&&setTimeout((()=>{m()}),200)})),document.addEventListener("visibilitychange",(function(){"visible"===document.visibilityState&&m()})),((e,t)=>{if(!e||d)return;d=!0;const n=r();n&&(n.postMessage({type:"RegisterOnUpdatedTab",mediaType:e}),n.onMessage.addListener((function(e){e.data&&"OnUpdatedTab"===e.type&&t(e.data.changeInfo)})))})(c,b)):console.error("Failed to initialize communications port")},t?v(!0):(chrome.runtime.sendMessage(e,{type:"SupportsGreaselion"},(function(r){!chrome.runtime.lastError&&r&&r.supported&&(t=chrome.runtime.connect(e,{name:"Greaselion"}),v(!0))})),setTimeout((()=>{t||(t=chrome.runtime.connect("jidkidbbcafjabdphckchenhfomhnfma",{name:"Greaselion"}),v(!0))}),100)),console.info("Greaselion script loaded: vimeo.ts"))})();