Greasy Fork

网易新闻视频地址解析

网易新闻内容 视频地址 解析

目前为 2021-11-02 提交的版本。查看 最新版本

// ==UserScript==
// @name         网易新闻视频地址解析
// @namespace    http://fulicat.com
// @version      1.0.2
// @url           https://greasyfork.org/zh-CN/scripts/382595
// @description  网易新闻内容 视频地址 解析
// @author       Jack.Chan
// @match        *://c.m.163.com/news/*
// @match        *://3g.163.com/news/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function init() {
        var $player = document.querySelector('#player');
        if ($player && $player.src) {
            var url = $player.src, title = document.title;
            var style = [];
            style.push('<style type="text/css">');
            style.push('.parser{position:fixed;right:0;bottom:0;left:0px;z-index:99999;background-color:#fff;box-shadow: 0 -3px 10px 2px #ccc;}');
            style.push('.parser-list{max-width:750px;margin:0 auto;padding-bottom:10px;background-color:rgba(255,255,255,0.95);line-height:2em;overflow:hidden;}');
            style.push('.parser-list>dt{background-color:#eee;font-size:18px;padding:10px;}');
            style.push('.parser-list>dd{border-top:1px #ccc solid;padding:10px 10px;}');
            style.push('.parser-list a{color:#3d93ef;}');
            style.push('.parser-list a:hover{text-decoration:underline;}');
            style.push('.g-body-wrap{margin-top:0;}');
            style.push('.m-video-player{position:static;top:0;margin-left:0;}');
            style.push('</style>');

            var html = [];
            html.push('<dl class="parser-list">');
            html.push('<dt>视频:'+ title +'</dt>');
            html.push('<dd><a target="_blank" href="'+ url +'">'+ title +'</a>&nbsp;&nbsp;&nbsp;<a target="_blank" href="'+ url +'" download="'+ title +'">下载</a></dd>');
            html.push('</dl>');

            var $parser = document.createElement('div');
            $parser.id = 'parser';
            $parser.className = 'parser';
            $parser.innerHTML = style.join('') + html.join('');
            document.body.appendChild($parser);


            var $items = document.querySelectorAll('li.js-open-newsapp');
            $items && $items.forEach(function(item) {
                (function(li){
                    var nli = li.cloneNode(true);
                    nli.onclick = function(e) {
                        e.preventDefault();
                        e.stopPropagation();
                        var param = this.dataset.param;
                        if (param) {
                            location.href = '//c.m.163.com/news/v/'+ param +'.html';
                        }
                        return false;
                    }
                    li.parentNode.replaceChild(nli, li);
                })(item);
            });

        }

        fixes();
    }

    function fixes() {
        try{
            document.querySelector('article[id^=article-]').style.cssText = '';
            //document.querySelector('article[id^=article-]').id = ''
            document.querySelector('.js-show-article').click(); //自动展开文章
            document.querySelector('.g-top-slider').remove();
            document.querySelector('.js-slider').remove();
            document.querySelector('.doc-footer-wrapper').remove();
            document.querySelector('.m-slider-footer').remove();
        }catch(ex){}
    }

    if (location.href.startsWith('https://c.m.163.com/news/') || location.href.startsWith('https://3g.163.com/news/')) {
        fixes();
        setTimeout(function(){
            init();
        }, 1000);
    }

})();