// ==UserScript==
// @name 网易新闻视频地址解析
// @namespace http://fulicat.com
// @version 1.0.4
// @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
// @downloadURL https://update.greasyfork.icu/scripts/382595/%E7%BD%91%E6%98%93%E6%96%B0%E9%97%BB%E8%A7%86%E9%A2%91%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90.user.js
// @updateURL https://update.greasyfork.icu/scripts/382595/%E7%BD%91%E6%98%93%E6%96%B0%E9%97%BB%E8%A7%86%E9%A2%91%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90.meta.js
// ==/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('');
var html = [];
html.push('
');
html.push('- ');
html.push('');
html.push('');
html.push('');
html.push('
'+ title +'
');
html.push(' ');
html.push('- '+ title +' 下载
');
html.push('
');
var $parser = document.createElement('div');
$parser.id = 'parser';
$parser.className = 'parser';
$parser.innerHTML = style.join('') + html.join('');
document.body.appendChild($parser);
var $btnActions = document.querySelectorAll('.js-btn-action');
$btnActions.forEach(function(item, itemIndex){
(function($el, index) {
console.log($el, index);
$el.addEventListener('click', function(e){
e.preventDefault();
e.stopPropagation();
var action = this.dataset.action;
var data = '';
switch(action) {
case 'all':
data = title +'\n\r'+ url;
break;
case 'title':
data = title;
break;
case 'url':
data = url;
break;
}
if (data) {
copy(data, function() {
$el.innerText = '复制成功';
setTimeout(function() {
$el.innerText = $el.dataset.text;
}, 2500);
})
}
})
})(item);
});
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 copy(text, callback) {
if (text !== undefined) {
var $textarea = document.createElement('textarea');
$textarea.setAttribute('readonly', 'readonly');
$textarea.style.cssText = 'position:absolute;left:-999px;top:-999px;width:1px;height:1px;';
$textarea.value = text;
document.body.appendChild($textarea);
$textarea.select();
setTimeout(function() {
document.execCommand('copy');
if (typeof callback === 'function') {
callback(text);
document.body.removeChild($textarea);
}
}, 300);
}
}
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);
}
})();