// ==UserScript==
// @name 💡WebPreview - 信息直达
// @namespace https://ez118.github.io/
// @version 0.2
// @description 支持国内主流搜索引擎的搜索结果快速预览(直达网页文本大纲)
// @author ZZY_WISU
// @match https://*.bing.com/*
// @match https://www.baidu.com/*
// @match https://www.so.com/*
// @connect *
// @license GNU GPLv3
// @icon https://cn.bing.com/sa/simg/favicon-trans-bg-blue-mg.ico
// @run-at document-end
// @grant GM_xmlhttpRequest
// @grant GM_download
// @grant GM_registerMenuCommand
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @downloadURL none
// ==/UserScript==
var ReaderFlag1 = false; /* 用于存储阅读器元素是否被创建 */
var ReaderFlag2 = false; /* 用于存储阅读器是否为开启状态 */
function runAsync(url,send_type,data_ry) {
var p = new Promise((resolve, reject)=> {
GM_xmlhttpRequest({
method: send_type, url: url, headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"}, data: data_ry,
onload: function(response){resolve(response.responseText);}, onerror: function(response){reject("请求失败");}
});
});
return p;
}
function escapeHtml(str) {
return str.replace(/[&<>"']/g, function(match) {
switch (match) {
case '&':
//return '&';
return '&';
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '\'':
return ''';
default:
return '';
}
});
}
function getWebContents(txt) {
var links;
var images;
var content;
/* 获取所有链接 */
/*links = txt.match(/href\=\"(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g);
for(let i = 0; i < links.length; i ++) {
links[i] = links[i].replace("href=\"", "");
}*/
links = [];
txt.replace(/]*href=['"]([^'"]+)[^>]*>/g,function(match, capture){
links.push(capture);
});
//console.log(links);
/* 获取所有图片 */
//images = txt.match(/]*src=[\"]([^\"]+)[\"][^<>]*>/im);
images = [];
txt.replace(/
]*src=['"]([^'"]+)[^>]*>/g,function(match, capture){
images.push(capture);
});
//console.log(images);
/* 获取文本 */
content = txt.replace(/<\/div>/g, "\n").replace(/<\/table>/g, "\n")
content = content.replace(/<\/h3>/g, "\n").replace(/<\/p>/g, "