Skip to content

Commit

Permalink
popup 4.4.1 textboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
lkytal committed Jun 18, 2020
1 parent b6e933a commit e351ff7
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 458 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to all the scripts will be documented in this file.

## Popup Search

* 4.4.1: Support display in textboxes
* 4.3.2: Fixed translate target language.
* 4.3.0: Provide 'Copy' button.
* 4.2.7: Https icons.
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* [Popup Search](https://git.oschina.net/coldfire/GM/raw/master/popsearch.user.js)
* [Text to link](https://git.oschina.net/coldfire/GM/raw/master/linkMix.user.js)
* [Tieba enhance](https://git.oschina.net/coldfire/GM/raw/master/tieba_enhance.user.js)
* [Scroll with mouse plus](https://git.oschina.net/coldfire/GM/raw/master/scroll.user.js)
* [Select like Opera](https://git.oschina.net/coldfire/GM/raw/master/select.user.js)
* [Search Image with Google & Baidu](https://git.oschina.net/coldfire/GM/raw/master/img.user.js)
* [Discuz in new tab](https://git.oschina.net/coldfire/GM/raw/master/discuz_in_tab.user.js)
Expand Down
42 changes: 12 additions & 30 deletions linkMix.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,29 @@
// @updateURL https://git.oschina.net/coldfire/GM/raw/master/meta/linkMix.meta.js
// @downloadURL https://git.oschina.net/coldfire/GM/raw/master/linkMix.user.js
// ==/UserScript==
"use strict";

"use strict";
;
var clearLink, excludedTags, linkFilter, linkMixInit, linkPack, linkify, observePage, observer, setLink, urlPrefixes, url_regexp, xPath;

url_regexp = /((https?:\/\/|www\.)[\x21-\x7e]+[\w\/=]|\w([\w._-])+@\w[\w\._-]+\.(com|cn|org|net|info|tv|cc|gov|edu)|(\w[\w._-]+\.(com|cn|org|net|info|tv|cc|gov|edu))(\/[\x21-\x7e]*[\w\/])?|ed2k:\/\/[\x21-\x7e]+\|\/|thunder:\/\/[\x21-\x7e]+=)/gi;

urlPrefixes = ['http://', 'https://', 'ftp://', 'thunder://', 'ed2k://', 'mailto://', 'file://'];

clearLink = function (event) {
var j, len, link, prefix, ref, ref1, url;
link = (ref = event.originalTarget) != null ? ref : event.target;

if (!(link != null && link.localName === "a" && ((ref1 = link.className) != null ? ref1.indexOf("textToLink") : void 0) !== -1)) {
return;
}

url = link.getAttribute("href"); //console.log url

url = link.getAttribute("href");
//console.log url
for (j = 0, len = urlPrefixes.length; j < len; j++) {
prefix = urlPrefixes[j];

if (url.indexOf(prefix) === 0) {
return;
}
}

if (url.indexOf('@') !== -1) {
return link.setAttribute("href", "mailto://" + url);
} else {
Expand All @@ -64,41 +62,34 @@ document.addEventListener("mouseover", clearLink);

setLink = function (candidate) {
var ref, ref1, ref2, span, text;

if (candidate == null || ((ref = candidate.parentNode) != null ? (ref1 = ref.className) != null ? typeof ref1.indexOf === "function" ? ref1.indexOf("textToLink") : void 0 : void 0 : void 0) !== -1 || candidate.nodeName === "#cdata-section") {
return;
}

text = candidate.textContent.replace(url_regexp, '<a href="$1" target="_blank" class="textToLink">$1</a>');

if (((ref2 = candidate.textContent) != null ? ref2.length : void 0) === text.length) {
return;
}

span = document.createElement("span");
span.innerHTML = text;
return candidate.parentNode.replaceChild(span, candidate);
};

excludedTags = "a,svg,canvas,applet,input,button,area,pre,embed,frame,frameset,head,iframe,img,option,map,meta,noscript,object,script,style,textarea,code".split(",");
xPath = "//text()[not(ancestor::" + excludedTags.join(') and not(ancestor::') + ")]";

xPath = `//text()[not(ancestor::${excludedTags.join(') and not(ancestor::')})]`;

linkPack = function (result, start) {
var i, j, k, ref, ref1, ref2, ref3, startTime;
startTime = Date.now();

while (start + 10000 < result.snapshotLength) {
for (i = j = ref = start, ref1 = start + 10000; ref <= ref1 ? j <= ref1 : j >= ref1; i = ref <= ref1 ? ++j : --j) {
setLink(result.snapshotItem(i));
}

start += 10000;

if (Date.now() - startTime > 2500) {
return;
}
}

for (i = k = ref2 = start, ref3 = result.snapshotLength; ref2 <= ref3 ? k <= ref3 : k >= ref3; i = ref2 <= ref3 ? ++k : --k) {
setLink(result.snapshotItem(i));
}
Expand All @@ -112,39 +103,31 @@ linkify = function (node) {

linkFilter = function (node) {
var j, len, tag;

for (j = 0, len = excludedTags.length; j < len; j++) {
tag = excludedTags[j];

if (tag === node.parentNode.localName.toLowerCase()) {
return NodeFilter.FILTER_REJECT;
}
}

return NodeFilter.FILTER_ACCEPT;
};

observePage = function (root) {
var tW;
tW = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
//+ NodeFilter.SHOW_ELEMENT,
tW = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { //+ NodeFilter.SHOW_ELEMENT,
acceptNode: linkFilter
}, false);

while (tW.nextNode()) {
setLink(tW.currentNode);
}
};

observer = new window.MutationObserver(function (mutations) {
var Node, j, k, len, len1, mutation, ref;

for (j = 0, len = mutations.length; j < len; j++) {
mutation = mutations[j];

if (mutation.type === "childList") {
ref = mutation.addedNodes;

for (k = 0, len1 = ref.length; k < len1; k++) {
Node = ref[k];
observePage(Node);
Expand All @@ -156,11 +139,10 @@ observer = new window.MutationObserver(function (mutations) {
linkMixInit = function () {
if (window !== window.top || window.document.title === "") {
return;
} //console.time('a')


linkify(document.body); //console.timeEnd('a')

}
//console.time('a')
linkify(document.body);
//console.timeEnd('a')
return observer.observe(document.body, {
childList: true,
subtree: true
Expand Down
2 changes: 1 addition & 1 deletion meta/popsearch.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @name:zh Popup Search: 快捷搜索
// @author lkytal
// @namespace Lkytal
// @version 4.4.0
// @version 4.4.1
// @icon https://github.com/lkytal/GM/raw/master/icons/search.png
// @homepage https://lkytal.github.io/
// @homepageURL https://lkytal.github.io/GM
Expand Down
20 changes: 0 additions & 20 deletions meta/scroll.meta.js

This file was deleted.

Loading

0 comments on commit e351ff7

Please sign in to comment.