JAV 网站在线联动

enjoy yourself

// ==UserScript==
// @name        JAV 网站在线联动
// @namespace    m-team javbus javlibrary jable connector
// @version      2.1.5
// @description  enjoy yourself
// @license      1285500
// @author       1285500
// @include     *://jable.tv/*
// @include     *://www.javbus.com/*
// @include     *://www.javlibrary.com/*
// @include     *://kp.m-team.cc/*
// @grant       none
// ==/UserScript==

(function() {
    var getAVID = function(title) {
        // console.log("Parse: " + title);
        var regs = [
            new RegExp('^([a-zA-Z]{2,5}-[0-9]{2,5}) {0,1}.*'), // dmm
            new RegExp('(259LUXU-[0-9]{3,4})','i'), // LUXU259
            new RegExp('([0-9]{3}[a-zA-Z]{3,4}-[0-9]{3,4})'), // 300MIUM 200GANA 332NAMA 300NTK ...
            new RegExp('([0-9]{5,6}[\-\_]{1}[0-9]{2,3})'), // 1pondo
            // few
            // Carib
            // HEYZO
        ];

        for(var i=0; i<regs.length; i++){
            var avid = regs[i].exec(title);
            if(avid != null){
              let _vid = (avid[1].replace('_','-')).toUpperCase();
              console.log("Parsed: " + _vid);
              return _vid;
            }
        }

        return null;
    };

    var append_link = function() {
      var jav_site_root = "https://www.javbus.com";
      var jab_site_root = "https://jable.tv";
      var jlib_site_root = "https://www.javlibrary.com"
      var mt_site_root = "https://kp.m-team.cc"

      var jav_regex = RegExp(jav_site_root + "/(.+)");
      var jlib_regex = RegExp(jlib_site_root + "\/(.+)\/?v=");
      var jlib_index_regex = RegExp(jlib_site_root + "\/(.+)\/vl_.*");

      var jab_regex = RegExp(jab_site_root + "/videos/(.+)/");
      var mteam_regex = RegExp(mt_site_root + "/(.+)/(.+)"); //https://kp.m-team.cc/browse/adult https://kp.m-team.cc/detail/XXXXXX


      var jav_paths = jav_regex.exec(location.href);
      var jlib_paths = jlib_regex.exec(location.href);
      var jlib_index = jlib_index_regex.exec(location.href);
      var jab_paths = jab_regex.exec(location.href);
      if (jav_paths !== null) {
          let avid = document.querySelector('.header').nextElementSibling.innerHTML;
          // javbus
          var mteam_root = document.createElement('pre');
          var mteam = document.createElement('a');
          mteam.style = 'color:#880000';
          mteam.innerHTML = ' PT搜索';
          mteam.href = mt_site_root + '/browse/adult?keyword=' + avid;
          mteam.target = '_blank';
          mteam_root.appendChild(mteam);
          var target = document.querySelector('.info');

          if (target.classList.contains('modified')) return;
          target.classList.add('modified');

          target.insertBefore(mteam_root, target.querySelectorAll('p')[1]);

          var jlib = document.createElement('a');
          jlib.innerHTML = ' 评分';
          jlib.href = jlib_site_root + '/cn/vl_searchbyid.php?keyword=' + avid;
          jlib.target = '_blank';
          jlib.style = 'color:#880000';
          mteam_root.appendChild(jlib);

          var jabplay = document.createElement('a');
          jabplay.innerHTML = ' 播放视频';
          jabplay.href = jab_site_root + '/videos/' + avid + '/';
          jabplay.target = '_blank';
          jabplay.style = 'color:#880000';
          mteam_root.appendChild(jabplay);

          return;
      } else if (jlib_index !== null) {
          // jlib index page
          let elements = document.querySelectorAll(".video");
          if (elements != null) {
                for (var i = 0, element; element = elements[i]; i++) {
                    let title = element.querySelector('.id').innerText;
                    var avid = getAVID(title);
                    if (avid != null) {
                      console.log("Attr:", avid)

                      var target = element.querySelector(".toolbar");

                      if (target.classList.contains('modified')) continue;
                      target.classList.add('modified');

                      var mteam_root = document.createElement('pre');
                      target.appendChild(mteam_root);

                      var jab = document.createElement('a');
                      jab.innerHTML = '<img src="https://assets-cdn.jable.tv/assets/icon/favicon.ico" height="16px" width="16px" />';
                      jab.href = jab_site_root + '/videos/' + avid + '/';
                      jab.target = '_blank';
                      mteam_root.appendChild(jab);
                    }
                }
          }

      } else if (jlib_paths !== null) {
          // jlib
          var target = document.querySelector('#video_id');

          if (target.classList.contains('modified')) return;
          target.classList.add('modified');

          let avid = target.querySelectorAll('td')[1].innerText;
          var mteam_root = document.createElement('pre');
          var mteam = document.createElement('a');
          mteam.style = 'color:#880000';
          mteam.innerHTML = ' PT搜索';
          mteam.href = mt_site_root + '/browse/adult?keyword=' + avid;
          mteam.target = '_blank';
          mteam_root.appendChild(mteam);
          target.insertBefore(mteam_root, target.querySelectorAll('table')[0]);

          var javbus = document.createElement('a');
          javbus.innerHTML = ' 预览';
          javbus.href = jav_site_root + '/' + avid;
          javbus.target = '_blank';
          javbus.style = 'color:#880000';
          mteam_root.appendChild(javbus);

          var jabplay = document.createElement('a');
          jabplay.innerHTML = ' 播放视频';
          jabplay.href = jab_site_root + '/videos/' + avid + '/';
          jabplay.target = '_blank';
          jabplay.style = 'color:#880000';
          mteam_root.appendChild(jabplay);

          return;
      } else if (jab_paths !== null) {
          // jable
          let avid = jab_paths[1];
          var mteam_root = document.createElement('pre');
          var mteam = document.createElement('a');
          mteam.style = 'color:#fff';
          mteam.innerHTML = ' PT搜索';
          mteam.href = mt_site_root + '/browse/adult?keyword=' + avid;
          mteam.target = '_blank';
          mteam_root.appendChild(mteam);
          var target = document.querySelector('.header-left');

          if (target.classList.contains('modified')) return;
          target.classList.add('modified');

          target.insertBefore(mteam_root, target.querySelectorAll('p')[1]);

          var jlib = document.createElement('a');
          jlib.innerHTML = ' 评分';
          jlib.href = jlib_site_root + '/cn/vl_searchbyid.php?keyword=' + avid;
          jlib.target = '_blank';
          jlib.style = 'color:#fff';
          mteam_root.appendChild(jlib);

          return;
      }

      var mteam_paths = mteam_regex.exec(location.href);
      if (mteam_paths === null) {
          return;
      }
      switch(mteam_paths[1]) {
          case "browse":
              // List
              let elements = document.querySelector("table").rows; // HTMLCollection
              if (elements != null) {
                for (var i = 0, element; element = elements[i]; i++) {
                    if (element.querySelectorAll('img[alt$="Censored"]').length === 0) {
                      continue;
                    }
                    let title = element.querySelectorAll('a[href*="/detail"]')[0].innerText;
                    var avid = getAVID(title);
                    if (avid != null) {
                      console.log("Attr:", avid)
                      var target = element.querySelector('button').parentElement;

                      if (target.classList.contains('modified')) continue;
                      target.classList.add('modified');

                      var mteam_root = document.createElement('pre');
                      mteam_root.style.margin = '4px';
                      target.appendChild(mteam_root);

                      var jav = document.createElement('a');
                      jav.innerHTML = '<img style="height: 20px; width: 20px; border-radius: 50%; border: 1px solid #2f4879; object-fit: cover;" src="http://www.javbus.com/favicon.ico" />';
                      jav.href = jav_site_root + '/' + avid;
                      jav.target = '_blank';
                      jav.style.marginRight = '2px';
                      mteam_root.appendChild(jav);


                      var jlib = document.createElement('a');
                      jlib.innerHTML = '<img style="height: 20px; width: 20px; border-radius: 50%; border: 1px solid #2f4879; object-fit: cover;" src="'+ jlib_site_root + '/favicon.ico" />';
                      jlib.href = jlib_site_root + '/cn/vl_searchbyid.php?keyword=' + avid;
                      jlib.target = '_blank';
                      jlib.style.marginRight = '2px';
                      mteam_root.appendChild(jlib);

                      var jab = document.createElement('a');
                      jab.innerHTML = '<img style="height: 20px; width: 20px; border-radius: 50%; border: 1px solid #2f4879; object-fit: cover;" src="https://assets-cdn.jable.tv/assets/icon/favicon.ico" />';
                      jab.href = jab_site_root + '/videos/' + avid + '/';
                      jab.target = '_blank';
                      jab.style.marginRight = '2px';
                      mteam_root.appendChild(jab);
                    }
                }
              }
              return;
          case "detail":
              // Detail
              if (/\sCensored/.test(document.documentElement.innerHTML)) {
                  var avid = getAVID(document.querySelector('.title').textContent.match(/(.+?) /)[1])
                    if (avid != null) {
                      var jsearch = document.createElement('a');
                      jsearch.innerHTML = '预览';
                      jsearch.href = jav_site_root + '/' + avid;
                      jsearch.target = '_blank';
                      jsearch.style = 'color:#880000';
                      var jlib = document.createElement('a');
                      jlib.innerHTML = '评分';
                      jlib.href = jlib_site_root + '/cn/vl_searchbyid.php?keyword=' + avid;
                      jlib.target = '_blank';
                      jlib.style = 'color:#880000';
                      var msearch = document.createElement('a');
                      msearch.innerHTML = '站内搜索';
                      msearch.href = mt_site_root + '/browse/adult?keyword=' + avid;
                      msearch.target = '_blank';
                      msearch.style = 'color:#880000';
                      var jabplay = document.createElement('a');
                      jabplay.innerHTML = '播放视频';
                      jabplay.href = jab_site_root + '/videos/' + avid + '/';
                      jabplay.target = '_blank';
                      jabplay.style = 'color:#880000';
                      var target = document.querySelector('.title');

                      if (target.classList.contains('modified')) return;
                      target.classList.add('modified');

                      var mteam_root = document.createElement('pre');
                      target.appendChild(mteam_root);
                      mteam_root.appendChild(document.createTextNode(' ['));
                      mteam_root.appendChild(jsearch);
                      mteam_root.appendChild(document.createTextNode('] ['));
                      mteam_root.appendChild(jlib);
                      mteam_root.appendChild(document.createTextNode('] ['));
                      mteam_root.appendChild(jabplay);
                      mteam_root.appendChild(document.createTextNode('] ['));
                      mteam_root.appendChild(msearch);
                      mteam_root.appendChild(document.createTextNode(']'));
                    }
              }
              return;
      }
    }
    new MutationObserver(append_link).observe(document, {childList: true, subtree: true});
})();