知乎网页助手油猴脚本扩展:复制禁止转载文章,直接下载知乎视频

  • A+

知乎网页助手,这个油猴脚本有可能是当前最好用的知乎扩展,~

 

这个可能可能是功能最全面的知乎助手了~

注意:知乎网页助手是油猴脚本........

 

知乎网页助手功能介绍:

 

1、知乎网页助手知乎站外链接直接跳转至目标网址

2、知乎网页助手自动展开问题全部信息,同时展示所有回答

3、知乎网页助手去除知乎网页中的广告

4、知乎网页助手可以直接下载知乎网页中短视频

5、知乎网页助手禁止转载也能复制文章,解除知乎复制限制-划词复制(鼠标左键划?#39318;?#21160;添加到剪切板)

 

(鼠标左键划?#39318;?#21160;添加到剪切板)【注:支持Tampermonke4.0以上版本】【这可能是功能最全面的知乎助手了】

 

 

greasyfork地址:https://greasyfork.org/zh-CN/scripts/384172

怎样安装知乎网页助手脚本?

用户脚本是什么?
用户脚本是?#27426;?#20195;码,它们能够优化您的网页浏览体验。安装之后,有些脚本能为网站添?#26377;?#30340;功能,有些能使网站的界面更加易用,有些则能隐藏网站?#25103;?#20154;的部分内容。在 Greasy Fork 上的用户脚本都是由用户编写并向全世界发表的,您可以免费安装,轻松体验。

第一步:安装一个用户脚本管理器

Chrome 上的 Tampermonkey
要使用用户脚本,您首先需要安装一个用户脚本管理器。根据您使用的浏览器不同,可用的用户脚本管理器也有所不同。

Chrome:Tampermonkey 或 Violent monkey
Firefox:Greasemonkey、Tampermonkey
或 Violentmonkey
Safari:Tampermonkey
Microsoft Edge:Tampermonkey
Opera:Tampermonkey
或 Violentmonkey
Maxthon:Violentmonkey
Dolphin:Tampermonkey
UC:Tampermonkey
Qupzilla?#28023;?#19981;需要额外软件)
AdGuard?#28023;?#19981;需要额外软件)
第二步:安装一个用户脚本

用户脚本的安装按钮
浏览此网站 查找您想尝试的用户脚本。最流行的用户脚本有:

网盘自动填写密码【威力加强版】 - 智能融合网盘密码到网址中,打开网盘链接时不再需要手动复制密码,并自动提交密码,一?#28902;?#36890;无阻。同时记录网盘信息,当你再次打开该分享文件时,不再需要去找提取码,同时可追溯网盘地址的来源。
吾爱破解论坛_百度网盘链接激活 && 提取码自动补全 - 激活吾爱破解论坛中的百度网盘链接,并自动补全提取码然后跳转到分享地址
网页限制解除(精简优化版) - 解除大部分网站禁止复制、剪切、选择文本、右键菜单的限制。
百度网盘直接下载助手修改版 - 网盘内和分享页均显示[下载助手]按钮,支持获取直接下载链接+压缩下载链接;

Pixiv 增强 - 专注沉浸式体验,1.屏蔽广告,直接访问热门图片 2.使用users入り的方式搜索 3.搜索pid和uid 4.显示原?#25216;?#23610;寸,图片重命名,下载原图|gif图|动图帧zip|多图zip 5.显示画师id、画师背景图 6.自动加载评论 7.对动态标记作品类型 8.去除重定向 9.单页排序 10.控制面板选择想要的功能 github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。
在您找到想要的用户脚本后,点击用户脚本页面?#19979;?#33394;的安装按钮,您的用户脚本管理器将向您确认是否安装。

第三步:使用用户脚本
现在您可以访问这个用户脚本所针对的网站,脚本应该已经自动启动和生效。在试用?#27426;问?#38388;之后,您可以回?#25509;?#25143;脚本发表的页面,给用户脚本的作者留下反馈。

知乎网页助手油猴脚本扩展:复制禁止转载文章,直接下载知乎视频

 

以下是【知乎】网页助手.user.js的源代码:

// ==UserScript==
// @name 【知乎】网页助手
// @namespace zhihu_helper_tool
// @version 1.0.1
// @description 功能介绍:1、知乎站外链接直接跳转至目标网址;2、自动展开问题全部信息,同时展示所有回答;3、去除知乎网页中的广告;4、知乎网页中短视频下载;5、解除知乎复制限制-划词复制(鼠标左键划?#39318;?#21160;添加到剪切板)【注:支持Tampermonke4.0以上版本】【这可能是功能最全面的知乎助手了】
// @author broom,王超
// @icon data:image/ico;base64,AAABAAIAEBAAAAEAIAAoBQAAJgAAACAgAAABACAAKBQAAE4FAAAoAAAAEAAAACAAAAABACAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAA6IYLxOuIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/6IYLxOuIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//jWuP/xq2b/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64kQ/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7///////bJn//riA7/64gO//GrZv/riA7/64kQ///////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//CoX//+/fz/64gO/++gUP//////64oX///////riA7/////////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7///////bQrf//////8rFx/+uKF///////64kT/+uIDv/riA7//////+uIDv/riA7/64gO/+uIDv/riA7/64gO//K3fv//////8rV7/+uIDv/rihf//////+uJE//riA7/64gO///////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7//////+uIDv/riA7/64oX///////riRD/64gO/+uJEP//////64gO/+uIDv/riA7/64gO//vo2P///////////////////////////+uKF///////64kQ/+uIDv/riRD//////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv//////64gO/+uIDv/rihf//////+uIDv/riA7/64kT///////riA7/64gO/+uIDv/riA7/7ZU1/+uMHf/riRP//////+uJE//riA7/64oX///////riA7/64gO/+uKFf//////64gO/+uIDv/riA7/64gO//3z6//xrWv/64sY///////riA7/64gO/+uKF///////64oV/+uKFf/rjBv//////+uIDv/riA7/64gO/+uIDv/0wZD//v39//7+/v/+/v7//v7+///////rihf////////////////////////////riA7/64gO/+uIDv/riA7/7ZU1///////wp17/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/voVH/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/6IYLxOuIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/6IYLxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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/64gO/+uIDv/riA7/64gO/++dRv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/9suk////////////9tCu/+uIDv/riA7/64gO/+uIDv/riA7/64gO/++iU//riA7/64gO/+uIDv/riA7/+uLM//rizP/tlTT/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/99W2////////////8a1r/+uIDv/riA7/64gO/+uIDv/zvIf/+d7G/+uIDv/riA7/64gO/+uLGv/++/n///////328f/xsG7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/rjB3/++ze///////87uL/64kQ/+uIDv/riA7/8Kdd//79/P/64Mn/64gO/+uMH//////////////////76dn/////////////////////////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/vpFj//v7+///////xsG7/64gO/+6XO//99vD///////TClP/riA7/64wf/////////////////+2WOf/wqF///O/j///////////////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/42sD///////ncwv/sjSH/++rb///////64Mr/64kT/+uIDv/rjB/////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv///////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/++kVf///////vr4//nbwP//////++zf/+yPJf/riA7/64gO/+uMH////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//zu4v//////+uDJ//3z6//ulzv/64gO/+uIDv/riA7/64wf////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/9s2o///////2yJ7/7I0h/+uIDv/riA7/64gO/+uIDv/rjB/////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv///////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/ysXP///////rgyf/riA7/64gO/+uIDv/riA7/64gO/+uMH////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/++gUP///////PDl/+uIDv/riA7/64gO/+uIDv/riA7/64wf////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//K3ff////////////////////////////////////////////////////////////328P/rjB/////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv///////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/7I4k//zx5///////////////////////////////////////////////////////+dzB/+uMH////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/++vj//////+yNIf/riA7/64gO/+uIDv/riA7/64wf////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//338v//////7ZQy/+uIDv/riA7/64gO/+uIDv/rjB/////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv///////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/751I/+2TL//riA7/64gO/+uIDv/riA7//fXt///////umD7/64gO/+uIDv/riA7/64gO/+uMH////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/xrm3//v38//XEl//riA7/64gO/+uIDv/98un//////++dRv/riA7/64gO/+uIDv/riA7/64wf////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uJEP/87+P///////GrZv/riA7/64gO//zv5P//////755L/+uIDv/riA7/64gO/+uIDv/rjB/////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv///////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO//TAj///////+Ne5/+uKFf/rihX//O7h///////volP/64oV/+uKFf/rihX/64gO/+uMH////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO////////////64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/7ZQy//79/f/////////////////////////////////////////////////yt37/64wf///////////////////////////////////////////////////////riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/+uHL/////////////////////////////////////////////v38/++fTP/rjB///////////////////////////////////////////////////////+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/zuYP///////bOqv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+yPJ//99/L//fPr/+uJE//riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/++kVf/65tb/8Kpk/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO/+uIDv/riA7/64gO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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
// @match https://www.zhihu.com/*
// @match https://link.zhihu.com/*
// @match https://v.vzuu.com/video/*
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @run-at document-end
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_info
// @grant GM_download
// ==/UserScript==

(function() {
'use strict';
if(window.top != window.self){
return;
}
var window_url = window.location.href;
var website_host = window.location.host;

//直接跳转到目标网页
if(website_host == "link.zhihu.com"){
var regRet = location.search.match(/target=(.+?)(&|$)/);
if(regRet && regRet.length==3){
location.href = decodeURIComponent(regRet[1]);
}
return;
}

if(window_url.indexOf("https://www.zhihu.com/question/") != -1) {
autoExpandQuestionInfo();
}
//自动展开问题全部信息,同时展示所有回答
function autoExpandQuestionInfo() {
$('.Button.QuestionRichText-more.Button--plain').click();
var moreAnswers = $('.QuestionMainAction');
if(moreAnswers.length > 0) {
moreAnswers[0].click();
}
}

//去除首页广告
function clearAdvert() {
$(".Pc-card").each(function(){
if($(this).find(".Banner-adTag").length != 0){
$(this).remove();
}
});
}

setInterval(function(){
clearAdvert();
}, 500);

//划词复制
$('body').mouseup(function(){
var txt = window.getSelection?window.getSelection():document.selection.createRange().text;
GM_setClipboard(txt);
});
})();
/**
* 避免重复造轮子
* 集成插件:下载知乎视频
* greasyfork地址:https://greasyfork.org/zh-CN/scripts/39206
* 版本:V1.13
* */
(async () => {
if (window.location.host == 'www.zhihu.com') return;

const playlistBaseUrl = 'https://lens.zhihu.com/api/videos/';
const videoBaseUrl = 'https://v.vzuu.com/video/';
const videoId = window.location.pathname.split('/').pop(); // 视频id
const menuStyle = 'transform:none !important; left:auto !important; right:-0.5em !important;';
const playerSelector = '#player';
const controlBarSelector = playerSelector + ' > div:first-child > div:first-child > div:last-child > div:last-child > div:first-child';
const svgDownload = '<path d="M9.5,4 H14.5 V10 H17.8 L12,15.8 L6.2,10 H9.5 Z M6.2,18 H17.8 V20 H6.2 Z"></path>';
const svgCircle = '<circle cx="12" cy="12" r="8" fill="none" stroke-width="2" stroke="#555" />' +
'<text x="50%" y="50%" dy=".4em" text-anchor="middle" fill="#fff" font-size="9"></text>' +
'<path fill="none" r="8" transform="translate(12,12)" stroke-width="2" stroke="#fff" />';
const svgConvert = '<circle cx="12" cy="12" r="8" fill="none" stroke-width="2" stroke="#fff" />' +
'<path d="M13,7 L17,10 V11 H7 V10 H15 L12,8 Z M9,16 L7,14 V13 H17 V14 H9 L10,16 Z"></path>';
const wechatIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABuElEQVQ4T6WSv2uTQRjHv9/L+4YiCWpbo6jgJE5u4lIVAnYwl6SjIFLQv8HBRcFFBBcVoaXgIl0UMVwuBHR0sLSdClKogw5iqyIogjhE7itXUnkb3qagBzfc8+PzPPd9HuI/D7P5zrkJY8w5SSnJDWPMmrX21bAamwDv/R4ATwHYwWBJi0mSXK3Vaqt5IHrvxwG8BnB8SKUfks43m83lwRi22+27JK9FRwjhkDHmPoCLANTr9Q4kSfKI5JSk9XK5fKxarf7OQiLgE8mDfeNHSRWSaXxL+kByRNIzkl9IPq7X6++2Abz3PwFEDfLOCwC3JN0keRLAYQBfATwolUp3Yjexg5ckJ3Oy34QQrpN8TrKY419K0/RCFPG0pAWSJhsk6RLJGQB7AdyQNEXylKTbJM8CiHd2a4xXAMwBSLYgIYTLxpj5jDYjJMckfQZAkhVJ3/8ukvd+Q9IvAOMky5Kmo2i7LOq3TUC32z0aQjhjrX1CUtHW6XT2S3rf/8JOnIfbVnkwyjk3SbKzg4gLhUKhOhQQgc65EyTv9cd4pL8bowAmGo3Gyq6AvN5brda+YrFYsda+/SdAFvoH5C+l3GRotdcAAAAASUVORK5CYII=';
let videos = []; // 存储各?#30452;?#29575;的视频信息
let format = []; // 下载的格式; ts, mp4
let blobs = null; // 存储视频段
let ratio;
let errors = 0;

do {
await wait(500);
}
while (!document.querySelector(controlBarSelector + '> div:nth-last-of-type(1)') || !document.querySelector(controlBarSelector + '> div:nth-last-of-type(1)').querySelectorAll('button')[0]);

const domControlBar = document.querySelector(controlBarSelector);
const domFullScreenBtn = document.querySelector(controlBarSelector + '> div:nth-last-of-type(1)');
let domDownloadBtn = domFullScreenBtn.cloneNode(true); // 克隆全屏按钮为下载按钮
let downloading = false;

function wait(time) {
return new Promise(function (resolve, reject) {
setTimeout(resolve, time);
});
}

function fetchRetry(url, options = {}, times = 1, delay = 1000, checkStatus = true) {
return new Promise((resolve, reject) => {
// fetch 成功处理函数
function success(res) {
if (checkStatus && !res.ok) {
failure(res);
}
else {
resolve(res);
}
}

// 单?#38382;?#36133;处理函数
function failure(error) {
times--;

if (times) {
setTimeout(fetchUrl, delay);
}
else {
reject(error);
}
}

// 总体失败处理函数
function finalHandler(error) {
throw error;
}

function fetchUrl() {
return fetch(url, options)
.then(success)
.catch(failure)
.catch(finalHandler);
}

fetchUrl();
});
}

function getBrowerInfo() {
let browser = (function (window) {
let document = window.document;
let navigator = window.navigator;
let agent = navigator.userAgent.toLowerCase();
// IE8+支持.返回浏览器渲染当前文档所用的模式
// IE6,IE7:undefined.IE8:8(兼容模式返回7).IE9:9(兼容模式返回7||8)
// IE10:10(兼容模式7||8||9)
let IEMode = document.documentMode;
let chrome = window.chrome || false;
let system = {
// user-agent
agent: agent,
// 是否为IE
isIE: /trident/.test(agent),
// Gecko内核
isGecko: agent.indexOf('gecko') > 0 && agent.indexOf('like gecko') < 0,
// webkit内核
isWebkit: agent.indexOf('webkit') > 0,
// 是否为标准模式
isStrict: document.compatMode === 'CSS1Compat',
// 是否支持subtitle
supportSubTitle: function () {
return 'track' in document.createElement('track');
},
// 是否支持scoped
supportScope: function () {
return 'scoped' in document.createElement('style');
},

// 获取IE的版本号
ieVersion: function () {
let rMsie = /(msie\s|trident.*rv:)([\w.]+)/;
let match = rMsie.exec(agent);
try {
return match[2];
} catch (e) {
return IEMode;
}
},
// Opera版本号
operaVersion: function () {
try {
if (window.opera) {
return agent.match(/opera.([\d.]+)/)[1];
}
else if (agent.indexOf('opr') > 0) {
return agent.match(/opr\/([\d.]+)/)[1];
}
} catch (e) {
return 0;
}
}
};

try {
// 浏览器类型(IE、Opera、Chrome、Safari、Firefox)
system.type = system.isIE ? 'IE' :
window.opera || (agent.indexOf('opr') > 0) ? 'Opera' :
(agent.indexOf('chrome') > 0) ? 'Chrome' :
//safari也提供了专门的判定方式
window.openDatabase ? 'Safari' :
(agent.indexOf('firefox') > 0) ? 'Firefox' :
'unknow';

// 版本号
system.version = (system.type === 'IE') ? system.ieVersion() :
(system.type === 'Firefox') ? agent.match(/firefox\/([\d.]+)/)[1] :
(system.type === 'Chrome') ? agent.match(/chrome\/([\d.]+)/)[1] :
(system.type === 'Opera') ? system.operaVersion() :
(system.type === 'Safari') ? agent.match(/version\/([\d.]+)/)[1] :
'0';

// 浏览器外壳
system.shell = function () {
if (agent.indexOf('edge') > 0) {
system.version = agent.match(/edge\/([\d.]+)/)[1] || system.version;
return 'Edge';
}
// 遨游浏览器
if (agent.indexOf('maxthon') > 0) {
system.version = agent.match(/maxthon\/([\d.]+)/)[1] || system.version;
return 'Maxthon';
}
// QQ浏览器
if (agent.indexOf('qqbrowser') > 0) {
system.version = agent.match(/qqbrowser\/([\d.]+)/)[1] || system.version;
return 'QQBrowser';
}
// 搜狗浏览器
if (agent.indexOf('se 2.x') > 0) {
return '搜狗浏览器';
}

// Chrome:也可以使用window.chrome && window.chrome.webstore判断
if (chrome && system.type !== 'Opera') {
let external = window.external;
let clientInfo = window.clientInformation;
// 客户端语言:zh-cn,zh.360下面会返回undefined
let clientLanguage = clientInfo.languages;

// 猎豹浏览器:或者agent.indexOf("lbbrowser")>0
if (external && 'LiebaoGetVersion' in external) {
return 'LBBrowser';
}
// 百度浏览器
if (agent.indexOf('bidubrowser') > 0) {
system.version = agent.match(/bidubrowser\/([\d.]+)/)[1] ||
agent.match(/chrome\/([\d.]+)/)[1];
return 'BaiDuBrowser';
}
// 360极速浏览器和360安全浏览器
if (system.supportSubTitle() && typeof clientLanguage === 'undefined') {
let storeKeyLen = Object.keys(chrome.webstore).length;
let v8Locale = 'v8Locale' in window;
return storeKeyLen > 1 ? '360极速浏览器' : '360安全浏览器';
}
return 'Chrome';
}
return system.type;
};

// 浏览器名称(如果是壳浏览器,则返回壳名称)
system.name = system.shell();
// 对版本号进行过?#26031;?#22788;理
// System.version = System.versionFilter(System.version);

} catch (e) {
// console.log(e.message);
}

return system;

})(window);

if (browser.name == undefined || browser.name == '') {
browser.name = 'Unknown';
browser.version = 'Unknown';
}
else if (browser.version == undefined) {
browser.version = 'Unknown';
}
return browser;
}

function bytesToSize(bytes) {
let n = Math.log(bytes) / Math.log(1024) | 0;
return (bytes / Math.pow(1024, n)).toFixed(0) + ' ' + (n ? 'KMGTPEZY'[--n] + 'B' : 'Bytes');
}

// 下载 m3u8 文件
async function downloadM3u8(url) {
const res = await fetchRetry(url, {}, 3);
const m3u8 = await res.text();
let i = 0;

blobs = [];
ratio = 0;
errors = 0;

// 初始化进度显示
domDownloadBtn.querySelector('svg').innerHTML = svgCircle;
updateProgress(0);

m3u8.split('\n').forEach(function (line) {
if (line.match(/\.ts/)) {
blobs[i] = undefined;
downloadTs(url.replace(/\/[^\/]+?$/, '/' + line), i++);
}
});
}

// 下载 m3u8 文件中的单个 ts 文件
async function downloadTs(url, order) {
let res;
let blob;

try {
res = await fetchRetry(url, {}, 5);
blob = await res.blob();

} catch (e) {
if (++errors == 1) {
resetDownloadIcon();
alert('下载视频失败,请重新下载。');
}
return;
}

ratio++;
blobs[order] = blob;

errors ? resetDownloadIcon() : updateProgress(Math.round(100 * ratio / blobs.length));

store();
}

// 保存视频文件
async function store() {
for (let [index, blob] of blobs.entries()) {
if (blob === undefined) return;
}

let blob = new Blob(blobs, {type: 'video/h264'});

blobs = null;

if (format == 'mp4-transform') {
domDownloadBtn.querySelector('svg').innerHTML = svgConvert;
blob = await convertToMp4(blob);
}

downloading = false;
downloadBlob(blob);
}

// 下载 blob 里的视频
function downloadBlob(blob) {
let name = (new Date()).valueOf() + '.mp4'; // + format
let navigator = window.navigator;
let url;

// ArrayBuffer -> blob
if (blob instanceof ArrayBuffer) {
blob = new Blob([blob]);
}

// 结束进度显示
resetDownloadIcon();

// edge
if (navigator && navigator.msSaveBlob) {
navigator.msSaveBlob(blob, name);
}
else {
url = URL.createObjectURL(blob);
downloadUrl(url, name);
}
}

// 下载指定url的资源
async function downloadUrl(url, name = (new Date()).valueOf() + '.mp4') {
let browser = getBrowerInfo();

// Greasemonkey 需要把 url 转为 blobUrl
if (GM_info.scriptHandler == 'Greasemonkey') {
let res = await fetchRetry(url);
let blob = await res.blob();
url = URL.createObjectURL(blob);
}

// Chrome 可以使用 Tampermonkey 的 GM_download 函数绕过 CSP(Content Security Policy) 的限制
if (window.GM_download) {
GM_download({url, name});
}
else {
// firefox 需要禁用 CSP, about:config -> security.csp.enable => false
let a = document.createElement('a');
a.href = url;
a.download = name;
// a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

setTimeout(function () {
URL.revokeObjectURL(url);
}, 100);
}
}

// 重置下载图标
function resetDownloadIcon() {
domDownloadBtn.querySelector('svg').innerHTML = svgDownload;
}

// 更新下载进度界面
function updateProgress(percent) {
let r = 8;
let degrees = (percent == 100 ? 99.9999 : percent) / 100 * 360; // 进度对应的角度值
let rad = degrees * (Math.PI / 180); // 角度对应的弧度值
let x = (Math.sin(rad) * r).toFixed(2); // 极坐标转换成直角坐标
let y = -(Math.cos(rad) * r).toFixed(2);
let lenghty = Number(degrees > 180); // 大于180°时画大角度弧,小于180°时画小角度弧,(deg > 180) ? 1 : 0
let paths = ['M', 0, -r, 'A', r, r, 0, lenghty, 1, x, y]; // path 属性

domDownloadBtn.querySelector('svg > path').setAttribute('d', paths.join(' '));
domDownloadBtn.querySelector('svg > text').textContent = percent;
}

// load QRCode js
async function loadQrcode() {
if (!unsafeWindow.qrcode) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = 'https://cdn.rawgit.com/kazuhikoarase/qrcode-generator/3c72b1bb/js/qrcode.js';
script.addEventListener('load', () => {
resolve();
});
document.body.appendChild(script);
});
}
}

// load ffmpeg js
async function loadFfmpeg() {
if (!unsafeWindow.ffmpegJS) {
const res = await fetchRetry('https://cdn.rawgit.com/bgrins/videoconverter.js/42def8c4/build/ffmpeg.js');
const js = await res.text();
}
return unsafeWindow.ffmpegJS;
}

// ts blob -> mp4 blob
async function convertToMp4(blob) {
let hasError = false;
// const ffmpegJsUrl = 'https://cdn.rawgit.com/bgrins/videoconverter.js/42def8c4/build/ffmpeg.js';
// const ffmpegJsUrl = 'https://gitee.com/dntc/videoconverter.js/raw/master/build/ffmpeg.js';
const ffmpegJsUrl = 'https://coding.net/u/dntc/p/videoconverter.js/git/raw/master/build/ffmpeg.js';
const orgPrompt = unsafeWindow.prompt;
const buffer = await (new Response(blob)).arrayBuffer();
const fileData = new Uint8Array(buffer);
const importFfmpegJs = 'importScripts("' + ffmpegJsUrl + '");';
const workerJs = importFfmpegJs + `
function print(text) {
postMessage({
type: 'stdout',
data: text
});
}

onmessage = function(event) {
const message = event.data;

if (message.type === 'command') {
const module = {
files: message.files || [],
arguments: message.arguments || [],
print: print,
printErr: print,
TOTAL_MEMORY: message.TOTAL_MEMORY || false
};

postMessage({
type: 'start',
data: module.arguments.join(' ')
});

postMessage({
type: 'stdout',
data: 'Received command: ' + module.arguments.join(' ') +
((module.TOTAL_MEMORY) ? '. Processing with ' + module.TOTAL_MEMORY + ' bits.' : '')
});

const time = Math.floor((new Date()).getTime() / 1000);
const result = ffmpeg_run(module);
const totalTime = Math.floor((new Date()).getTime() / 1000) - time;

postMessage({
type: 'stdout',
data: 'Finished processing (took ' + totalTime + 'm)'
});

postMessage({
type : 'done',
data : result,
time : totalTime
});
}
};

postMessage({
type: 'ready'
});
`;
const workerBlob = new Blob([workerJs], {'type': 'application/javascript'});
const worker = new Worker(URL.createObjectURL(workerBlob));
const parseArguments = function (text) {
text = text.replace(/\s+/g, ' ');
let args = [];
// Allow double quotes to not split args.
text.split('"').forEach(function (t, i) {
t = t.trim();
if ((i % 2) === 1) {
args.push(t);
}
else {
args = args.concat(t.split(' '));
}
});
return args;
};

let files;

return new Promise(function (resolve, reject) {
worker.onmessage = function (event) {
const message = event.data;

if (message.type == 'ready') {
console.log('ffmpeg 格式转换代码加载完毕');

// worker.postMessage({
// type: 'command',
// arguments: ['-help']
// })

worker.postMessage({
type: 'command',
TOTAL_MEMORY: 268435456, // 256M, must be a power of 2
arguments: parseArguments('-i zhihu.ts -vf showinfo -strict -2 output.mp4'),
files: [
{
name: 'zhihu.ts',
data: fileData
}
]
});
}
else if (message.type == 'start') {
console.log('Worker has received command');
}
else if (message.type == 'stdout') {
console.log(message.data);
if (!hasError && message.data.indexOf('TOTAL_MEMORY') != -1) {
hasError = true;
alert('分配的内存不足,转换出错。');
}
}
else if (message.type == 'done') {
// finishConvert();
const files = message.data;
resolve(new Blob([files[0].data]));
}
};
});
}

// 获取视频信息
const res = await fetchRetry(playlistBaseUrl + videoId, {
headers: {
'referer': 'refererBaseUrl + videoId',
'authorization': 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20' // in zplayer.min.js of zhihu
}
}, 3);
const videoInfo = await res.json();

// 获取不同?#30452;?#29575;视频的信息
for (let [key, video] of Object.entries(videoInfo.playlist)) {
video.name = key;

if (!videos.find(v => v.width == video.width)) {
videos.push(video);
}
}

// 按?#30452;?#29575;大小排序
videos = videos.sort(function (v1, v2) {
return v1.width == v2.width ? 0 : (v1.width > v2.width ? 1 : -1);
}).reverse();

// 生成下载按钮图标
domDownloadBtn.querySelector('button:first-child').outerHTML = domFullScreenBtn.cloneNode(true).querySelector('button').outerHTML;
domDownloadBtn.querySelector('svg').innerHTML = svgDownload;

// 鼠标?#24405;?- 选择菜单项
domDownloadBtn.addEventListener('pointerup', event => {
let e = event.srcElement || event.target;

if (downloading) {
alert('当前正在执行下载任务,请等待任务完成。');
return;
}

downloadUrl(videos[0].play_url);
});

// 显示下载按钮
domControlBar.appendChild(domDownloadBtn);
})();

发表评论

:?: :razz: :sad::evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: