PlatinSport direct AceStream links

Obtain direct, clickable AceStream links on PlatinSport, bypassing url shorteners.

目前为 2023-08-22 提交的版本。查看 最新版本

// ==UserScript==
// @name        PlatinSport direct AceStream links
// @description Obtain direct, clickable AceStream links on PlatinSport, bypassing url shorteners.
// @namespace   StephenP
// @author   StephenP
// @grant     GM.registerMenuCommand
// @grant     GM.setValue
// @grant     GM.getValue
// @version     1.5
// @match https://www.platinsport.com/*
// @contributionURL https://nowpayments.io/donation/stephenpgreasyfork
// @license AGPL-3.0-or-later
// ==/UserScript==
getAdultContentVisible();
async function getAdultContentVisible(){
  var x=await GM.getValue("adultContentEnabled");
  if(x=="yes"){
    GM.registerMenuCommand("Hide the lists of adult contents on Platinsport", hideAdultContent, "H");
  }
  else{
    GM.registerMenuCommand("Show the lists of adult contents on Platinsport", showAdultContent, "S");
    removeAdultLinks();
  }
  createLinks();
  absoluteMode();
}
function hideAdultContent(){
  GM.setValue("adultContentEnabled","no");
	location.reload();
}
function showAdultContent(){
  GM.setValue("adultContentEnabled","yes");
  location.reload();
}
function removeAdultLinks(){
  var b=document.getElementsByClassName("fa-mars-double");
  if(b.length==1){
    b[0].parentNode.parentNode.remove();
  }
}
function createLinks(){
  if(!document.location.href.includes("/link/")){
    var links=document.getElementsByTagName("A");
    var bcvclinks=0;
    for(let link of links){
      if(link.href.includes("bc.vc")){
        bcvclinks++;
        let pos=link.href.indexOf("https://www.p");
        link.href=link.href.slice(pos);
      }
    }
    if(bcvclinks==0){
      links=document.getElementsByClassName("entry")[0].getElementsByTagName("a");
      let xhr = new XMLHttpRequest();
      xhr.open('GET', 'https://www.platinsport.com/link/'+(links.length-1).toString()+'.php', true);
      try {
        xhr.send();
        xhr.onload = () => {
          if (xhr.readyState === 4) {
            if (xhr.status === 200) {
              for(var i=1;i<=links.length;i++){
                if(i<10){
                  links[i-1].href="https://www.platinsport.com/link/0"+i+".php";
                }
                else{
                  links[i-1].href="https://www.platinsport.com/link/"+i+".php";
                }
              }
            } else {
              bewareTheShortener();
              console.log(xhr.status+xhr.statusText);
            }
          }
        };
        xhr.onerror = () => {
          bewareTheShortener();
          console.log(xhr.status+xhr.statusText);
        };
      } catch(err) {
        bewareTheShortener();
        console.log("Request failed");
      }
    }
  }
  else{
    var texts=document.getElementsByTagName("STRONG");
    var regexpLangs=/[\[]([A-Z][A-Z])[\]]/g
    var regexpLinks=/acestream:\/\/[a-f0-9]{40}/g
    let directLinks=document.body.querySelectorAll("a[href^='acestream:']");
    if(directLinks){
       for(let l of directLinks){
         //l.innerText+=l.href.replace("acestream://"," - ");
         l.innerText=l.innerText.replace(regexpLangs,replacerLangs);
       }
    }
    else{
      for(let t of texts){
        var link=null;
        t.innerHTML=t.innerHTML.replace(regexpLinks,replacerLinks);
        if(location.href.includes("/link")){
          t.innerHTML=t.innerHTML.replace(regexpLangs,replacerLangs);
        }
      }
    }
  }
}
function replacerLinks(match, offset, string) {
  return "<a style=\"color: yellow; line-height: normal\" href=\""+match+"\">"+match.replace("acestream://","")+"</a>";
}

function replacerLangs(match, p1, offset, string) {
  return getFlagEmoji(p1);
}
//Following function taken mostly from https://dev.to/jorik/country-code-to-flag-emoji-a21
function getFlagEmoji(countryCode) {
  if(countryCode==="UK"){
    countryCode="GB"
  }
  const codePoints = countryCode
    .toUpperCase()
    .split('')
    .map(char =>  127397 + char.charCodeAt());
  return String.fromCodePoint(...codePoints);
}
async function bewareTheShortener(){
  let lastDate = await GM.getValue("lastDate","01-01-1970");
  const date = new Date();
  let currentDate = date.getDate()+"-"+(date.getMonth()+1)+"-"+date.getFullYear();
  if(currentDate!=lastDate){
    if(confirm("PLATINSPORT DIRECT ACESTREAM LINKS SCRIPT:\n\nDirect AceStream links are not available today: if you click on the links, you will be redirected through a link shortener that MAY contain viruses. Please, be sure to have an ad blocker installed and reject any popup asking to accept notifications.\n\nClick OK to dismiss this note for today.\nClick Cancel to display this note again today.")==true){
      GM.setValue("lastDate",currentDate);
    }
  }
}
function absoluteMode() {//taken from https://greasyfork.org/it/scripts/23772-absolute-enable-right-click-copy/ (BSD Licence)
  [].forEach.call(
      ['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'],
      function(event) {
          document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
      }
  );
}