Greasy Fork

Greasy Fork is available in English.

CSDN摸鱼影视

CSDN摸鱼影视,只限于CSDN进行摸鱼,摸鱼行动请量力而行

当前为 2022-11-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         CSDN摸鱼影视
// @namespace    http://greasyfork.org/
// @version      1.0
// @description  CSDN摸鱼影视,只限于CSDN进行摸鱼,摸鱼行动请量力而行
// @author       Roc.w
// @match        http*://*.csdn.net/*
// @icon         https://g.csdnimg.cn/static/logo/favicon32.ico
// @grant        none
// @license      AGPL License
// ==/UserScript==

console.log('欢迎使用树懒脚本! 联系作者:[email protected]')
console.log('采用纯原生JS写法 高性能、高可用、高兼容!')

init()

/*************************一条华丽的分割线 基层代码块*****************************/

//初始化元素
function init() {
  //创建按钮元素
  craeateButtonElement()
  //创建消息提示元素
  craeateMsgElement()
  //创建搜索元素
  craeateSearchElement()
}

//创建按钮元素
function craeateButtonElement(){
  let btnParam = {
        ele: document.createElement('div'),
        css: "display: flex;" +
             "cursor: pointer;" +
             "position: fixed;" +
             "right:40px;" +
             "top: 100px;"+
             "background: #aaa;" +
             "width: 50px;" +
             "height: 50px;" +
             "z-index:1000;" +
             "border-radius: 100%;",
        iconcss:"margin: auto;"+
              "width: 35px;"+
              "height: 35px;"+
              "line-height: 35px;"+
              "background: #fff;"+
              "animation:kite 5s infinite;"+
              "text-align: center;"+
              "font-size: 22px;"+
              "border-radius: 100%;"
    };

    document.querySelector('body').appendChild(((ele)=> {
        ele.id = 'sloth-topic';
        ele.innerHTML = '<div style="'+btnParam.iconcss+'">🎶🦥</div>';
        ele.style.cssText = btnParam.css;
        return ele;
    })(btnParam.ele));

    //动态创建keyframes动画
    //document.styleSheets[0].insertRule(`@keyframes kite{100%{transform:rotate(360deg);}}`,0)
    const style = document.createElement('style')
    style.appendChild(document.createTextNode(`@keyframes kite{100%{transform:rotate(360deg);}}`));
    document.getElementById('sloth-topic').appendChild(style);

    //按钮点击操作
    document.getElementById("sloth-topic").addEventListener("click", function(){
      start();
    });
}

//创建消息元素
function craeateMsgElement(){
  let msgParam = {
        ele: document.createElement('div'),
        css: "background: rgba(0,0,0,0.5);" +
              "position: fixed;" +
              "inset: 0px;" +
              "margin: auto;" +
              "padding: 10px;" +
              "border-radius: 5px;" +
              "color: #fff;" +
              "font-size: 14px;" +
              "letter-spacing: 1.5px;"+
              "display: none;"+
              "z-index: 99999;"
    };
    document.querySelector('body').appendChild(((ele)=> {
        ele.id = 'sloth-msg';
        ele.innerHTML = '';
        ele.style.cssText = msgParam.css;
        return ele;
    })(msgParam.ele));
}

//消息提示
function msg(msg,timeout=2500){
  document.getElementById('sloth-msg').style.display='inline-table';
  document.getElementById('sloth-msg').innerHTML=msg;
  setTimeout(() => {
    document.getElementById('sloth-msg').style.display='none';
  }, timeout);
}

//创建搜索元素
function craeateSearchElement(){
  let searchParam = {
        ele: document.createElement('div'),
        boxcss: "background: #888;" +
                "position: fixed;" +
                "inset: -50% 0px 0px 0px;" +
                "margin: auto;" +
                "width: 500px;" +
                "height: 50px;" +
                "border-radius: 10px;" +
                "display: none;" +
                "padding-left: 7px;"+
                "z-index: 999;",
        inputcss:"margin: auto;"+
                  "flex: 0.75;" +
                  "height: 35px;" +
                  "margin: auto;" +
                  "border: 0;" +
                  "border-radius: 10px 0 0 10px;" +
                  "padding: 4px;" +
                  "outline: none;" +
                  "font-size: 20px;",
          btncss:"flex: 0.25;" +
                  "margin: auto;" +
                  "height: 50px;" +
                  "background: #4e6ef2;" +
                  "text-align: center;" +
                  "line-height: 50px;" +
                  "cursor: pointer;" +
                  "color: #fff;" +
                  "border-radius: 0 10px 10px 0;"
    };
    document.querySelector('body').appendChild(((ele)=> {
        ele.id = 'sloth-search-box';
        ele.innerHTML = '<input id="sloth-search-input" style="'+searchParam.inputcss+'"><div  id="sloth-search-btn" style="'+searchParam.btncss+'">解析一下</div>';
        ele.style.cssText = searchParam.boxcss;
        return ele;
    })(searchParam.ele));

    //按钮点击操作
    document.getElementById("sloth-search-btn").addEventListener("click", function(){
      search();
    });
}

//HTTP请求
function request(url, param, callback,type='GET') {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4) {
            if((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304){
                callback && callback(xhr.responseText);
            }
        }
    }
    xhr.open(type, url, true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xhr.send(param);
}

/*************************一条华丽的分割线 业务代码块*****************************/

//点击开始按钮
function start(){
  var txt = document.getElementById('sloth-search-box').style.display;
  if (txt=='none') {
    document.getElementById('sloth-search-box').style.display='flex'
  }else{
    document.getElementById('sloth-search-box').style.display='none'
  }
}

//解析一下,并植入CSDN
function search(){
  var url = document.getElementById('sloth-search-input').value
  if(url==''){
    return msg('请输入解析地址');
  }
  //植入iframe
  let iframeParam = {
        ele: document.createElement('iframe'),
        css: "width: 100%;"+
             "height: 300px;"
  };
  document.getElementsByTagName('pre')[0].prepend(((ele)=> {
        ele.id = 'sloth-iframe';
        ele.innerHTML = '';
        ele.frameborder='0';
        ele.scrolling='no'
        ele.src='https://jx.jsonplayer.com/player/?url='+url
        ele.style.cssText = iframeParam.css;
        return ele;
    })(iframeParam.ele));
    document.getElementById('sloth-search-box').style.display='none'
    document.getElementById('sloth-search-input').value='';
   //追加代码行号
   var children = document.getElementsByTagName('pre')[0].children
    for (let i = 0; i < children.length; i++) {
      if (children[i].className.search('pre-numbering')>-1) {
       var len = children[i].children.length;
        for (let j = 0; j < 14; j++) {
          len++
          //children[i].append('<li style="color: rgb(153, 153, 153);">'+len+'</li>')
          $(children[i]).eq($(children[i]).length - 1).append('<li style="color: rgb(153, 153, 153);">'+len+'</li>')
        }
      }
    }
}