diff --git a/CHANGELOG.md b/CHANGELOG.md
index b03645b..c10d1e3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/README.md b/README.md
index d1e869f..fabe95b 100644
--- a/README.md
+++ b/README.md
@@ -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)
diff --git a/linkMix.user.js b/linkMix.user.js
index 01cf148..d877d97 100644
--- a/linkMix.user.js
+++ b/linkMix.user.js
@@ -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 {
@@ -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, '$1 ');
-
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));
}
@@ -112,25 +103,20 @@ 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);
}
@@ -138,13 +124,10 @@ observePage = function (root) {
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);
@@ -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
diff --git a/meta/popsearch.meta.js b/meta/popsearch.meta.js
index 499bd9d..f9b4d3b 100644
--- a/meta/popsearch.meta.js
+++ b/meta/popsearch.meta.js
@@ -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
diff --git a/meta/scroll.meta.js b/meta/scroll.meta.js
deleted file mode 100644
index 743eb6f..0000000
--- a/meta/scroll.meta.js
+++ /dev/null
@@ -1,20 +0,0 @@
-// ==UserScript==
-// @name Scroll with Mouse Plus
-// @description Scroll pages when mouse hover on scrollbar
-// @author lkytal
-// @namespace Lkytal
-// @version 1.5.0
-// @homepage https://lkytal.github.io/
-// @homepageURL https://lkytal.github.io/GM
-// @include *
-// @exclude *pan.baidu.com/*
-// @icon https://github.com/lkytal/GM/raw/master/icons/scroll.png
-// @license AGPL
-// @grant GM_getValue
-// @grant GM_setValue
-// @grant GM_addStyle
-// @run-at document-end
-// @supportURL https://github.com/lkytal/GM/issues
-// @updateURL https://git.oschina.net/coldfire/GM/raw/master/meta/scroll.meta.js
-// @downloadURL https://git.oschina.net/coldfire/GM/raw/master/scroll.user.js
-// ==/UserScript==
\ No newline at end of file
diff --git a/popsearch.user.js b/popsearch.user.js
index ea6189b..e3319ee 100644
--- a/popsearch.user.js
+++ b/popsearch.user.js
@@ -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
@@ -37,11 +37,12 @@
// @updateURL https://git.oschina.net/coldfire/GM/raw/master/meta/popsearch.meta.js
// @downloadURL https://git.oschina.net/coldfire/GM/raw/master/popsearch.user.js
// ==/UserScript==
-"use strict";
+"use strict";
;
var CopyText,
GetOpt,
+ GetTextboxSelection,
InTextBox,
OnEngine,
OpenSet,
@@ -69,7 +70,9 @@ var CopyText,
parseTranslationGoogle,
popData,
hasProp = {}.hasOwnProperty;
+
window.$ = window.jQuery = jQuery.noConflict(true);
+
popData = {
count: 0,
mouseIn: 0,
@@ -128,7 +131,7 @@ popData = {
}, {
id: "Iframe_st",
text: "在Iframe中显示/ Activate in iframes",
- defaultValue: 0
+ defaultValue: 1
}, {
id: "Dis_st",
text: "显示于文字上方 / Display above selection",
@@ -137,6 +140,10 @@ popData = {
id: "Ctrl_st",
text: "仅按下Ctrl时显示 / Only when ctrl pressed",
defaultValue: 0
+ }, {
+ id: "Textbox_st",
+ text: "不在文本框内显示 / Ignore selections in textboxes",
+ defaultValue: 0
}, {
id: "userEngine_st",
text: "自定义引擎 / Enable Customize",
@@ -157,6 +164,7 @@ popData = {
href: "https://www.google.com/search?q=${text}%20site:${domain}"
}]
};
+
popData.engines = [{
id: "Open_st",
title: "Open As Url",
@@ -266,7 +274,7 @@ popData.engines = [{
log = function (msg) {
popData.count += 1;
- return console.log("Popup Msg " + popData.count + " : " + msg);
+ return console.log(`Popup Msg ${popData.count} : ${msg}`);
};
isChrome = function () {
@@ -275,19 +283,16 @@ isChrome = function () {
fixPos = function (sel, e) {
var eventLeft, eventTop, fix, m_left, offsetLeft, offsetTop, offsets;
- offsets = get_selection_offsets(sel);
+ offsets = get_selection_offsets(sel, e);
offsetTop = offsets[0];
offsetLeft = offsets[1];
-
if (e != null) {
eventTop = e.pageY;
eventLeft = e.pageX;
-
if (Math.abs(offsetTop - eventTop) > 50) {
//log offsetTop + " : " + offsetLeft + " <==> " + eventTop + " : " + eventLeft
offsetTop = eventTop - 8;
}
-
if (Math.abs(offsetLeft - eventLeft) > 50) {
//translate
offsetLeft = eventLeft + 10;
@@ -295,25 +300,20 @@ fixPos = function (sel, e) {
} else {
$('#showUpBody').css('margin-left', '60px');
}
-
if (GetOpt('Dis_st')) {
//UpSide
offsetTop = offsetTop - 2 - $('#ShowUpBox').height();
-
if (offsetTop - document.documentElement.scrollTop < 40) {
offsetTop = document.documentElement.scrollTop + 40;
}
} else {
offsetTop += 1.1 * offsets[2];
}
-
m_left = $('#ShowUpBox').width();
fix = 0;
-
if (offsetLeft - m_left < 4) {
fix = 4 - offsetLeft + m_left;
}
-
$('#ShowUpBox').css("top", offsetTop + "px").css("left", offsetLeft - m_left + fix + "px");
return $('#popupTip').css('margin-left', m_left - 20 - fix);
};
@@ -333,7 +333,6 @@ OnEngine = function (e) {
} else {
GM_openInTab($(this).data('link'), !GetOpt("Focus_st"));
}
-
$('#ShowUpBox').fadeOut(200);
return false;
};
@@ -341,24 +340,20 @@ OnEngine = function (e) {
PopupInit = function () {
var $DivBox, $icon, EngineList, engine, j, k, l, len, len1, len2, ref, ref1, ref2;
$('#ShowUpBox').remove();
- EngineList = " ";
+ EngineList = ` `;
ref = popData.engines;
-
for (j = 0, len = ref.length; j < len; j++) {
engine = ref[j];
- EngineList += " ";
+ EngineList += ` `;
}
-
if (GetOpt("userEngine_st")) {
ref1 = popData.userEngines;
-
for (k = 0, len1 = ref1.length; k < len1; k++) {
engine = ref1[k];
- EngineList += " ";
+ EngineList += ` `;
}
}
-
- $('body').append(" ");
+ $('body').append(` `);
$DivBox = $('#ShowUpBox');
$DivBox.hide();
$DivBox.hover(function () {
@@ -370,7 +365,6 @@ PopupInit = function () {
clearTimeout(popData.timer);
popData.timer = setTimeout(TimeOutHide, 6000);
}
-
return popData.mouseIn = 0;
});
$('#showUpBody').on("mouseup", function (event) {
@@ -393,38 +387,30 @@ PopupInit = function () {
return event.stopPropagation();
});
ref2 = popData.engines;
-
for (l = 0, len2 = ref2.length; l < len2; l++) {
engine = ref2[l];
$icon = $("#" + engine.id + "Icon");
-
if (!GetOpt(engine.id)) {
$icon.hide();
}
}
-
$DivBox.find('.engine, .userEngine').on('click', OnEngine);
$('#transBtn').on("click", onTranslate);
-
if (!GetOpt('Trans_st')) {
$('#transBtn').hide();
}
-
$('#copy_btn').on("click", function () {
CopyText(popData.rawText);
return $('#ShowUpBox').fadeOut(200);
});
-
if (!GetOpt('copy_icon_st')) {
$('#copy_btn').hide();
}
-
if (GetOpt('Tab_st')) {
$DivBox.find('a').attr('target', '_blank');
} else {
$DivBox.find('a').attr('target', '_self');
}
-
if (GetOpt('Dis_st')) {
popData.tip = popData.tipUp;
return $DivBox.append('');
@@ -435,13 +421,13 @@ PopupInit = function () {
};
ajaxError = function (res) {
- return $('#transPanel').empty().append("
Translate Error: " + res.statusText + "
").show();
+ return $('#transPanel').empty().append(`Translate Error: ${res.statusText}
`).show();
};
onTranslate = function (event) {
event.preventDefault();
popData.bTrans = 1;
- $("#transPanel").empty().append("").show();
+ $("#transPanel").empty().append(``).show();
$('#popupWrapper').hide();
fixPos(document.defaultView.getSelection());
return doRequest(0, 2000);
@@ -449,20 +435,17 @@ onTranslate = function (event) {
doRequest = function (i, wait) {
var ErrHandle, lang;
-
ErrHandle = function () {
return doRequest(i + 1, wait + 2000);
};
-
if (i >= 2) {
ErrHandle = ajaxError;
}
-
lang = navigator.language || navigator.userLanguage || "zh-CN";
return GM_xmlhttpRequest({
method: 'POST',
url: 'https://translate.google.cn/translate_a/single',
- data: "client=gtx&dj=1&q=" + popData.text + "&sl=auto&tl=" + lang + "&hl=" + lang + "&ie=UTF-8&oe=UTF-8&source=icon&dt=t&dt=bd",
+ data: `client=gtx&dj=1&q=${popData.text}&sl=auto&tl=${lang}&hl=${lang}&ie=UTF-8&oe=UTF-8&source=icon&dt=t&dt=bd`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
@@ -475,86 +458,69 @@ doRequest = function (i, wait) {
parseTranslationGoogle = function (responseDetails) {
var PickMeaning, RLine, RTxt, Result, j, len, line, ref, sentence;
-
if (!popData.bTrans) {
return;
}
-
try {
RTxt = JSON.parse(responseDetails.responseText);
} catch (error) {
return ajaxError(responseDetails);
}
-
RLine = function () {
var j, len, ref, results;
ref = RTxt.sentences;
results = [];
-
for (j = 0, len = ref.length; j < len; j++) {
sentence = ref[j];
results.push(sentence.trans);
}
-
return results;
}().toString();
-
PickMeaning = function (list) {
var i, item, j, len, results;
results = [];
-
for (i = j = 0, len = list.length; j < len; i = ++j) {
item = list[i];
-
if (item.score > 0.005 || i < 3) {
results.push(item.word);
}
}
-
return results;
};
-
if (RTxt.dict != null) {
ref = RTxt.dict;
-
for (j = 0, len = ref.length; j < len; j++) {
line = ref[j];
- RLine += " " + (line.pos + " : " + PickMeaning(line.entry));
+ RLine += " " + `${line.pos} : ${PickMeaning(line.entry)}`;
}
}
-
- Result = "";
+ Result = ``;
$('#transPanel').empty().append(Result).show();
fixPos(document.defaultView.getSelection());
};
$(document).on("mousedown", function (event) {
popData.mousedownEvent = event;
-
if (popData.bTrans === 1) {
PopupInit();
}
-
return $('#ShowUpBox').fadeOut(200);
});
+
$(document).on("mouseup", function (event) {
if (event.which !== 1) {
return;
}
-
if (GetOpt('Ctrl_st') && !event.ctrlKey) {
return;
}
-
return ShowBar(event);
});
eventFromTextbox = function (eventList) {
var event, j, len;
-
for (j = 0, len = eventList.length; j < len; j++) {
event = eventList[j];
-
if (event != null) {
if ($(event.target).is('textarea, input, *[contenteditable="true"]')) {
//console.log $(event.target)
@@ -562,49 +528,51 @@ eventFromTextbox = function (eventList) {
}
}
}
-
return false;
};
InTextBox = function (selection) {
var area, j, len, ref;
-
if (isChrome()) {
return false;
}
-
ref = $('textarea, input, *[contenteditable="true"]', document);
-
for (j = 0, len = ref.length; j < len; j++) {
area = ref[j];
-
if (selection.containsNode(area, true)) {
return true;
}
}
-
return false;
};
+GetTextboxSelection = function () {
+ var textbox;
+ textbox = document.activeElement;
+ if (textbox.selectionEnd - textbox.selectionStart > 0) {
+ return textbox.value.substring(textbox.selectionStart, textbox.selectionEnd);
+ }
+ return "";
+};
+
ShowBar = function (event) {
var engine, j, k, len, len1, paraList, ref, ref1, sel, setHref;
sel = document.defaultView.getSelection();
-
if (InTextBox(sel) || eventFromTextbox([event, popData.mousedownEvent])) {
- return;
+ if (GetOpt("Textbox_st")) {
+ return;
+ }
+ popData.rawText = GetTextboxSelection();
+ } else {
+ popData.rawText = sel.toString();
}
-
- popData.rawText = sel.toString();
popData.text = encodeURIComponent(popData.rawText.trim());
-
if (popData.rawText === '') {
return;
}
-
if (GetOpt("AutoCopy_st")) {
CopyText(popData.rawText);
}
-
$('#transPanel').empty().hide();
paraList = {
"\\${rawText}": popData.rawText,
@@ -612,40 +580,31 @@ ShowBar = function (event) {
"\\${domain}": document.domain,
"\\${url}": location.href
};
-
setHref = function (engine) {
- var $engine, href, para, value; //log engine.id + " : " + engine.href
-
+ var $engine, href, para, value;
+ //log engine.id + " : " + engine.href
href = engine.href;
-
for (para in paraList) {
if (!hasProp.call(paraList, para)) continue;
value = paraList[para];
- href = href.replace(RegExp("" + para, "g"), value);
+ href = href.replace(RegExp(`${para}`, "g"), value);
}
-
$engine = $("#" + engine.id + "Icon");
return $engine.data('link', href);
};
-
ref = popData.engines;
-
for (j = 0, len = ref.length; j < len; j++) {
engine = ref[j];
setHref(engine);
}
-
ref1 = popData.userEngines;
-
for (k = 0, len1 = ref1.length; k < len1; k++) {
engine = ref1[k];
setHref(engine);
}
-
if (needPrefix(popData.rawText)) {
- $('#Open_stIcon').data('link', "http://" + popData.rawText.trim());
+ $('#Open_stIcon').data('link', `http://${popData.rawText.trim()}`);
}
-
popData.mouseIn = 0;
popData.bTrans = 0;
clearTimeout(popData.timer);
@@ -658,15 +617,12 @@ needPrefix = function (url) {
var j, len, prefix, urlPrefixes;
url = url.trim();
urlPrefixes = ['http://', 'https://', 'ftp://', 'file://', 'thunder://', 'ed2k://', 'chrome://'];
-
for (j = 0, len = urlPrefixes.length; j < len; j++) {
prefix = urlPrefixes[j];
-
if (url.indexOf(prefix) === 0) {
return 0;
}
}
-
return 1;
};
@@ -674,11 +630,9 @@ CopyText = function (selText) {
if (selText == null) {
selText = document.defaultView.getSelection().toString();
}
-
if ((typeof GM_info !== "undefined" && GM_info !== null ? GM_info.scriptHandler : void 0) === "Violentmonkey") {
return document.execCommand('copy');
}
-
try {
return GM_setClipboard(selText, "text");
} catch (error) {
@@ -705,7 +659,6 @@ OpenSet = function () {
if ($('#popup_setting_bg').length === 0) {
SettingWin();
}
-
return $('#popup_setting_bg').fadeIn(400);
};
@@ -713,44 +666,51 @@ SettingWin = function () {
var chsJSON, engJSON, engine, engineOptionList, generateEngineOption, generateOption, item, j, len, option, optionList, ref;
addAdditionalCSS();
$('#popup_setting_bg').remove();
-
generateOption = function (option) {
- return " " + option.text + " ";
+ return ` ${option.text} `;
};
-
optionList = function () {
var j, len, ref, results;
ref = popData.optionList;
results = [];
-
for (j = 0, len = ref.length; j < len; j++) {
option = ref[j];
results.push(generateOption(option));
}
-
return results;
}().join(' ');
-
generateEngineOption = function (engine) {
- return " " + engine.description + " ";
+ return ` ${engine.description} `;
};
-
engineOptionList = function () {
var j, len, ref, results;
ref = popData.engines;
results = [];
-
for (j = 0, len = ref.length; j < len; j++) {
engine = ref[j];
results.push(generateEngineOption(engine));
}
-
return results;
}().join(' ');
-
- engJSON = '[\n {\n id: "UserEngine",\n title: "Example Engine",\n description: "Example of user-defined engine",\n src: "http://lkytal.qiniudn.com/ic.ico",\n href: "https://www.google.com/search?q=${text}"\n }\n]';
- chsJSON = '[\n {\n id: "UserEngine",\n title: "Example Engine",\n description: "自定义引擎示例",\n src: "http://lkytal.qiniudn.com/ic.ico",\n href: "https://www.google.com/search?q=${text}"\n }\n]';
- $("body").append("");
+ engJSON = `[
+ {
+ id: "UserEngine",
+ title: "Example Engine",
+ description: "Example of user-defined engine",
+ src: "http://lkytal.qiniudn.com/ic.ico",
+ href: "https://www.google.com/search?q=\${text}"
+ }
+]`;
+ chsJSON = `[
+ {
+ id: "UserEngine",
+ title: "Example Engine",
+ description: "自定义引擎示例",
+ src: "http://lkytal.qiniudn.com/ic.ico",
+ href: "https://www.google.com/search?q=\${text}"
+ }
+]`;
+ $("body").append(``);
$("#popup_setting_bg, #popup_help_bg").hide();
$("#tabs_box > .popup_tab").on("click", function (e) {
$("#tabs_box > .popup_tab").removeClass("popup_selected");
@@ -774,15 +734,12 @@ SettingWin = function () {
return $("#chsContent").show();
});
ref = $("#popup_setting_win .setting_item");
-
for (j = 0, len = ref.length; j < len; j++) {
item = ref[j];
-
if (item != null) {
ReadOpt(item.id);
}
}
-
$("#popup_engines").val(GM_getValue("engineString", popData.defaultEngineString));
$("#popReset").click(function () {
if (confirm("Reset?")) {
@@ -792,25 +749,19 @@ SettingWin = function () {
$("#popHelp").click(function () {
return $("#popup_help_bg").fadeIn();
});
-
if (!GetOpt("userEngine_st")) {
$("#popup_tab3").hide();
}
-
$("#popup_save").click(function () {
var k, len1, ref1, userEngineString;
ref1 = $("#popup_setting_win .setting_item");
-
for (k = 0, len1 = ref1.length; k < len1; k++) {
item = ref1[k];
-
if (item != null) {
SaveOpt(item.id);
}
}
-
userEngineString = $("#popup_engines").val();
-
if (userEngineString !== "") {
try {
popData.userEngines = JSON.parse(userEngineString);
@@ -820,10 +771,8 @@ SettingWin = function () {
log(userEngineString);
}
}
-
return $("#popup_setting_bg").fadeOut(300, function () {
$("#popup_setting_bg").remove(); //force rebuild setting window
-
return PopupInit(); //rebuild toolbar
});
});
@@ -860,42 +809,31 @@ UpdateNotified = function () {
PopupLoad = function () {
var engine, j, k, len, len1, option, popupMenu, ref, ref1, setDefault, userEngineString;
-
if (window.self !== window.top || window.frameElement) {
if (!GM_getValue("Iframe_st", 0)) {
return;
}
}
-
addCSS();
-
if (GM_getValue("UpdateAlert", 0) < popData.codeVersion) {
setDefault = function (key, defaultValue) {
return GM_setValue(key, GM_getValue(key, defaultValue));
};
-
ref = popData.optionList;
-
for (j = 0, len = ref.length; j < len; j++) {
option = ref[j];
setDefault(option.id, option.defaultValue);
}
-
ref1 = popData.engines;
-
for (k = 0, len1 = ref1.length; k < len1; k++) {
engine = ref1[k];
setDefault(engine.id, engine.defaultState);
}
-
UpdateLog();
}
-
popData.defaultEngineString = JSON.stringify(popData.defaultEngines, null, 4);
-
if (GetOpt("userEngine_st")) {
userEngineString = GM_getValue("engineString", popData.defaultEngineString);
-
try {
popData.userEngines = JSON.parse(userEngineString);
} catch (error) {
@@ -903,10 +841,8 @@ PopupLoad = function () {
console.error(userEngineString);
}
}
-
PopupInit();
GM_registerMenuCommand("Popup Search Setting / 设置", OpenSet, 'p');
-
if (GM_getValue("PopupMenu", 0)) {
popupMenu = document.body.appendChild(document.createElement("menu"));
popupMenu.outerHTML = '';
@@ -920,39 +856,40 @@ PopupLoad = function () {
setTimeout(PopupLoad, 100);
addCSS = function () {
- return GM_addStyle("#ShowUpBox { all: unset; width: auto; height: auto; position: absolute; z-index: 10240; color: black; display: inline-block; line-height: 0; vertical-align: baseline; box-sizing: content-box; } #showUpBody { min-width: 20px; max-width: 750px; min-height: 20px; max-height: 500px; display: block; border:solid 2px rgb(144,144,144); border-radius:1px; background:rgba(252, 252, 252, 1); } #popupWrapper { all: unset; margin: 3px 2px 3.8px 2px; display:block; line-height: 0; font-size:0; } #transPanel { line-height: normal; width: auto; font-size: 16px; overflow: auto; display: none; } #popupWrapper > a { all: unset; margin: 0px 2px; } #popupWrapper img { all: unset; margin: 0px; height: 24px; width: 24px; border-radius: 0px; padding: 0px; display: inline-block; transition-duration: 0.1s; -moz-transition-duration: 0.1s; -webkit-transition-duration: 0.1s; } #popupWrapper img:hover { margin: -1px -1px; height: 26px; width: 26px; } #popupTip { display: inline-block; clear: both; height: 9px; width: 9px; } .tipUp { background: url(" + popData.icons.tipUp + ") 0px 0px no-repeat transparent; margin-top: -2px; margin-bottom: 0px; } .tipDown { background: url(" + popData.icons.tipDown + ") 0px 0px no-repeat transparent; margin-top: 0px; margin-bottom: -2px; } #ShowUpBox a { text-decoration: none; display: inline-block; }");
+ return GM_addStyle(`#ShowUpBox { all: unset; width: auto; height: auto; position: absolute; z-index: 10240; color: black; display: inline-block; line-height: 0; vertical-align: baseline; box-sizing: content-box; } #showUpBody { min-width: 20px; max-width: 750px; min-height: 20px; max-height: 500px; display: block; border:solid 2px rgb(144,144,144); border-radius:1px; background:rgba(252, 252, 252, 1); } #popupWrapper { all: unset; margin: 3px 2px 3.8px 2px; display:block; line-height: 0; font-size:0; } #transPanel { line-height: normal; width: auto; font-size: 16px; overflow: auto; display: none; } #popupWrapper > a { all: unset; margin: 0px 2px; } #popupWrapper img { all: unset; margin: 0px; height: 24px; width: 24px; border-radius: 0px; padding: 0px; display: inline-block; transition-duration: 0.1s; -moz-transition-duration: 0.1s; -webkit-transition-duration: 0.1s; } #popupWrapper img:hover { margin: -1px -1px; height: 26px; width: 26px; } #popupTip { display: inline-block; clear: both; height: 9px; width: 9px; } .tipUp { background: url(${popData.icons.tipUp}) 0px 0px no-repeat transparent; margin-top: -2px; margin-bottom: 0px; } .tipDown { background: url(${popData.icons.tipDown}) 0px 0px no-repeat transparent; margin-top: 0px; margin-bottom: -2px; } #ShowUpBox a { text-decoration: none; display: inline-block; }`);
};
addAdditionalCSS = function () {
if (popData.additionalCSSLoaded === 1) {
return;
}
-
popData.additionalCSSLoaded = 1;
return GM_addStyle("#popup_setting_bg { all: unset; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.2); position: fixed; left: 0px; top: 0px; z-index:102400; font-family: \"Hiragino Sans GB\", \"Microsoft Yahei\", Arial, sans-serif; display: -webkit-flex; display: flex; justify-content: center; align-items: center; } #popup_setting_win { all: unset; width: 760px; height: 90%; box-shadow: 0 0 10px #222; box-sizing: content-box !important; background: rgba(255, 255, 255, 0.98); overflow: hidden; display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; } #popup_title { font-size:24px; font-weight: bold; text-align: center; padding: 15px; background: #16A085; color: white; flex-shrink: 0; height: 40px; } #popup_content { flex-grow: 1; flex-shrink: 1; height: calc(100% - 70px); padding: 0px; display: -webkit-flex; display: -moz-flex; display: flex; justify-content: space-between; align-items: stretch; } #tabs_box { display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; flex-basis: 25%; flex-shrink: 0; background: #EEE; } .popup_tab { width: 100%; background: #EEE; padding: 15px; font-weight: bold; text-align: center; box-sizing: border-box; cursor: pointer; user-select: none; -moz-user-select: none; -webkit-user-select: none; } .popup_tab:hover { background: #ccc; } .popup_selected { border-right: none; background: #FFF; } .popup_selected:hover { background: #FFF; } #page_box { padding: 20px 30px; flex-grow: 1; flex-shrink: 1; max-height: 100%; display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; } #option_box { display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; align-items: stretch; flex-grow: 1; flex-shrink: 1; overflow-y: auto; } #option_box > div { scroll-behavior: smooth; flex-grow: 1; display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; align-items: stretch; } #popup_engines { flex-grow: 1; border: solid 2px #ddd; text-overflow: clip; white-space: pre; overflow-x: auto; overflow-y: auto; word-wrap: break-word; resize: none; } #editTitle { padding: 0px 0px 15px 0px; display: -webkit-flex; display: -moz-flex; display: flex; justify-content: space-between; } #editTitle div { flex-grow: 1; } #editTitle span { margin-left: 20px; color : #1ABC9C; cursor: pointer; } #btnArea { display: -webkit-flex; display: -moz-flex; display: flex; justify-content: flex-end; margin-top: 20px; flex-shrink: 0; } .setting_btn { display: inline-block; font-size: 16px; text-align: center; mix-width: 50px; padding: 4px 10px 4px 10px; border-radius: 2px; margin: 0px 0px 0px 20px; background: #1ABC9C; color: #fff; cursor: pointer; user-select: none; -moz-user-select: none; -webkit-user-select: none; } .setting_btn:hover { text-shadow: 0px 0px 2px #FFF; } .setting_item { min-height: 28px; font-size: 14px; margin: 5px 0px 10px 0px; display: -webkit-flex; display: -moz-flex; display: flex; align-items: center; } .setting_item > img { width: 24px; height: auto; margin-right: 7px; } .setting_item .text{ flex-grow: 1; font-size: 16px; } #popup_help_bg { all: unset; width: 100%; height: 100%; position: fixed; top: 0; left: 0; background: transparent; display: -webkit-flex; display: flex; justify-content: center; align-items: center; z-index: 10240000; } #popup_help_win { all: unset; width: 650px; height: 80%; box-shadow: 0 0 10px #222; box-sizing: content-box !important; background: rgba(255, 255, 255, 0.98); padding: 20px; display: -webkit-flex; display: flex; flex-direction: column; align-items: stretch; /*overflow: hidden;*/ } #popup_help_content { max-height: 100%; flex-grow: 1; display: -webkit-flex; display: flex; flex-direction: column; align-items: stretch; } #helpLang { flex-grow: 0; flex-shrink: 0; display: -webkit-flex; display: flex; border-bottom: solid 1px #ccc; } #helpLang span { padding: 8px 30px; margin-bottom: -1px; cursor: pointer; user-select: none; -moz-user-select: none; -webkit-user-select: none; } #helpLang span.popup_head_selected { border-top: solid 1px #ccc; border-left: solid 1px #ccc; border-right: solid 1px #ccc; border-bottom: solid 3px #FFF; } #help_box { overflow-y: auto; flex-grow: 1; flex-shrink: 1; margin-top: 15px; } #help_box > div { word-wrap: break-word; } #help_btnArea { flex-grow: 0; flex-shrink: 0; display: -webkit-flex; display: flex; justify-content: flex-end; margin-top: 20px; } #popup_update_bg { all: unset; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.2); position: fixed; left: 0px; top: 0px; z-index: 1024000; font-family: \"Hiragino Sans GB\", \"Microsoft Yahei\", Arial, sans-serif; display: -webkit-flex; display: flex; justify-content: center; align-items: center; } #popup_update_win { all: unset; width: 50%; height: 80%; box-shadow:0 0 10px #222; box-sizing: content-box !important; background: rgba(255, 255, 255, 0.98); overflow: hidden; font-size: 16px; display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; } #update_header { font-size: 24px; font-weight: bold; text-align: center; padding: 15px; background: #16A085; color: white; flex-shrink: 0; height: 40px; } #popup_update_content { flex-grow: 1; flex-shrink: 1; height: calc(100% - 70px); overflow: auto; padding: 15px; display: -webkit-flex; display: -moz-flex; display: flex; flex-direction: column; justify-content: space-between; align-items: stretch; } #update_texts{ flex-grow: 1; flex-shrink: 1; } #update_btnArea { flex-grow: 0; flex-shrink: 0; display: -webkit-flex; display: flex; justify-content: flex-end; margin-top: 20px; } .hidden { display: none; } .tgl { display: none; } .tgl, .tgl:after, .tgl:before, .tgl *, .tgl *:after, .tgl *:before, .tgl+.tgl-btn { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .tgl::-moz-selection, .tgl:after::-moz-selection, .tgl:before::-moz-selection, .tgl *::-moz-selection, .tgl *:after::-moz-selection, .tgl *:before::-moz-selection, .tgl+.tgl-btn::-moz-selection { background: none; } .tgl::selection, .tgl:after::selection, .tgl:before::selection, .tgl *::selection, .tgl *:after::selection, .tgl *:before::selection, .tgl+.tgl-btn::selection { background: none; } .tgl+.tgl-btn { outline: 0; display: inline-block; width: 4em; height: 2em; position: relative; cursor: pointer; } .tgl+.tgl-btn:after, .tgl+.tgl-btn:before { position: relative; display: inline-block; content: \"\"; width: 50%; height: 100%; } .tgl+.tgl-btn:after { left: 0; } .tgl+.tgl-btn:before { display: none; } .tgl:checked+.tgl-btn:after { left: 50%; } .tgl-flat+.tgl-btn { padding: 2px; -webkit-transition: all .2s ease; transition: all .2s ease; background: #fff; border: 4px solid #f2f2f2; border-radius: 2em; } .tgl-flat+.tgl-btn:after { -webkit-transition: all .2s ease; transition: all .2s ease; background: #f2f2f2; content: \"\"; border-radius: 1em; } .tgl-flat:checked+.tgl-btn { border: 4px solid #1ABC9C; } .tgl-flat:checked+.tgl-btn:after { left: 50%; background: #1ABC9C; }");
};
getLastRange = function (selection) {
var j, rangeNum, ref;
-
for (rangeNum = j = ref = selection.rangeCount - 1; ref <= 0 ? j <= 0 : j >= 0; rangeNum = ref <= 0 ? ++j : --j) {
if (!selection.getRangeAt(rangeNum).collapsed) {
return selection.getRangeAt(rangeNum);
}
}
-
return selection.getRangeAt(selection.rangeCount - 1);
};
-get_selection_offsets = function (selection) {
+get_selection_offsets = function (selection, e) {
var $test_span, Rect, lastRange, newRange;
- $test_span = $('x '); // "x" because it must have a height
-
- lastRange = getLastRange(selection);
- newRange = document.createRange();
- newRange.setStart(lastRange.endContainer, lastRange.endOffset);
- newRange.insertNode($test_span[0]);
- Rect = $test_span[0].getBoundingClientRect();
- $test_span.remove();
- return [Rect.top + window.scrollY, Rect.left + window.scrollX, 0, 0];
+ try {
+ $test_span = $('x ');
+ // "x" because it must have a height
+ lastRange = getLastRange(selection);
+ newRange = document.createRange();
+ newRange.setStart(lastRange.endContainer, lastRange.endOffset);
+ newRange.insertNode($test_span[0]);
+ Rect = $test_span[0].getBoundingClientRect();
+ $test_span.remove();
+ return [Rect.top + window.scrollY, Rect.left + window.scrollX, 0, 0];
+ } catch (error) {
+ return [e.pageY, e.pageX, 0, 0];
+ }
};
\ No newline at end of file
diff --git a/scroll.user.js b/scroll.user.js
deleted file mode 100644
index ec2ef2f..0000000
--- a/scroll.user.js
+++ /dev/null
@@ -1,188 +0,0 @@
-// ==UserScript==
-// @name Scroll with Mouse Plus
-// @description Scroll pages when mouse hover on scrollbar
-// @author lkytal
-// @namespace Lkytal
-// @version 1.5.0
-// @homepage https://lkytal.github.io/
-// @homepageURL https://lkytal.github.io/GM
-// @include *
-// @exclude *pan.baidu.com/*
-// @icon https://github.com/lkytal/GM/raw/master/icons/scroll.png
-// @license AGPL
-// @grant GM_getValue
-// @grant GM_setValue
-// @grant GM_addStyle
-// @run-at document-end
-// @supportURL https://github.com/lkytal/GM/issues
-// @updateURL https://git.oschina.net/coldfire/GM/raw/master/meta/scroll.meta.js
-// @downloadURL https://git.oschina.net/coldfire/GM/raw/master/scroll.user.js
-// ==/UserScript==
-
-function scrollPlus() {
- //###Customization: |可自定义的东西:
-
- //go directly to top/down page | 回到顶部按钮
- var goTopButton = 1;
-
- //Show the scrolling indicator box or not, "1" to show. | 1-显示提示条,其他-不显示。
- var scrollShowIndicator = 1;
-
- //Set the width of scroll-sensitive zone, "100" as full width, "10" as one tenth.
- // | “滚动触发区”宽度,区间:[0-100],100为屏宽,0为禁用,10为十分之一屏宽。
- var VScrollonWidth = 5;
-
- //Set the background of the indicator bar. | 提示条的背景,可以为“rgba()”带透明色式或“#xxxxxx”实颜色式或其他。
- var IndicBarBG = "rgba(29,163,63, 0.4)";
-
- //Set the height of "thickness" of the indicator bar. | 提示条的粗细度,单位为像素。
- var IndicBarH = 20;
-
- //Write here the width of the scrollbar (set in display properties) for highest accuracy.
- // | 在下面填写滚动条的宽度(也就是系统“显示属性”中的数字),这样能实现最高精确度。
- var ScrollbarWidth = 10;
-
- //Set a trigger for activation, 1-none, 2-Ctrl key, 3-middle 100px range.
- // | 在下面设置激活条件,1-无,2-按住 Ctrl 键,3-鼠标在页面中间100像素高度范围内。
- var activateCond = 1;
-
- //###Customization ends. 请不要更改下面代码。
- var scrollStartSWTM = -1;
-
- var factor;
- var b = null;
- var VScrollOn = 0;
- var delayed = 0;
-
- document.addEventListener('mousemove', function (event) {
- if (document.body.contentEditable == "true") {
- return;
- }
-
- var dheightMax = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
- var cwidthMax = Math.max(document.body.clientWidth, document.documentElement.clientWidth) - ScrollbarWidth;
- var cwinHeight = window.innerHeight;
- var scrollboxHeight = window.innerHeight - 2 * ScrollbarWidth;
-
- if (dheightMax > cwinHeight) {
- if (event.clientX > cwidthMax) {
- switch (activateCond) {
- case 1:
- VScrollOn = 1;
- break;
- case 2:
- if (event.ctrlKey)
- VScrollOn = 1;
- break;
- case 3:
- if (event.clientY > cwinHeight / 2 - 50 && event.clientY < cwinHeight / 2 + 50)
- VScrollOn = 1;
- break;
- }
- }
-
- if (event.clientX < ((1 - VScrollonWidth / 100) * cwidthMax)) VScrollOn = 0;
- }
-
- if (VScrollOn && ! delayed) {
- setTimeout(function () {
- if (VScrollOn) {
- delayed = 1;
- }
- else {
- delayed = 0;
- }
- }, 200);
-
- return;
- }
-
- if (VScrollOn) {
- if (scrollShowIndicator == 1) make_boxes();
-
- if (scrollStartSWTM != -1) {
- factor = (event.ctrlKey) ? dheightMax / scrollboxHeight / 2 : dheightMax / scrollboxHeight;
- if (b) {
- b.style.top = (event.clientY - IndicBarH / 2) + 'px';
- }
-
- var delta = factor * (event.clientY - scrollStartSWTM);
- document.body.scrollTop += delta;
- document.documentElement.scrollTop += delta;
- if (event.clientY + 20 > cwinHeight) {
- document.body.scrollTop += (factor * 10);
- document.documentElement.scrollTop += (factor * 10);
- }
- if (event.clientY > 0 && event.clientY < 20) {
- document.body.scrollTop -= (factor * 10);
- document.documentElement.scrollTop -= (factor * 10);
- }
- }
- scrollStartSWTM = event.clientY;
- }
- else {
- scrollStartSWTM = -1;
- if (b) setTimeout(function () { b.style.top = -200 + 'px'; }, 200);
-
- delayed = 0;
- }
- }, false);
-
- document.addEventListener('click', function () { VScrollOn = 0; }, false);
-
- function make_boxes() {
- if (!b) {
- b = document.createElement("div");
- b.setAttribute("id", "IndicatorBox");
- b.setAttribute("style", "width:" + VScrollonWidth + "%;background:" + IndicBarBG + ";min-height:" + IndicBarH + "px;text-align:center;position: fixed; top: -40px; right: 0;overflow: hidden; z-index: 102400;font-family:Arial !important;cursor:n-resize;cursor:ns-resize;");
- document.body.appendChild(b);
- b.addEventListener('click', function () { VScrollOn = 0; }, false);
- return true;
- }
- }
-
- function addToTop() {
- var a = document.createElement('a');
- a.id = 'scrollUpIco';
- a.textContent = 'Top';
- a.addEventListener('click', function () { window.scrollTo(0, document.body.scrollLeft); }, false);
- document.body.appendChild(a);
-
- var st = [
- "#scrollUpIco {",
- "position: fixed;",
- "z-index: 1024000;",
- "width: 50px;",
- "height: 50px;",
- "border-radius: 25px;",
- "bottom: 20px;",
- "right: 25px;",
- "line-height: 50px;",
- "text-align: center;",
- "font-weight: bold;",
- "background-color: rgba(0, 0, 0, 0.2);",
- "text-shadow: 0px 0px 5px #000000;",
- "color: #fff;",
- "text-decoration: none;",
- "-moz-user-select: none;",
- "-webkit-user-select: none;",
- "user-select: none;",
- "cursor: default;",
- "}",
- "#scrollUpIco:hover {",
- "background-color: rgba(0, 0, 0, 0.5);",
- "color: #fff !important;",
- "cursor: pointer;",
- "}",
- "#scrollUpIco:-webkit-full-screen {display: none}"
- ].join("\n");
-
- GM_addStyle(st);
- }
-
- if (goTopButton) addToTop();
-}
-
-if (!(window !== window.top || window.document.title === "")) {
- setTimeout(scrollPlus, 100);
-}
diff --git a/tieba_enhance.user.js b/tieba_enhance.user.js
index c55ba98..900aee6 100644
--- a/tieba_enhance.user.js
+++ b/tieba_enhance.user.js
@@ -25,6 +25,7 @@
// @updateURL https://git.oschina.net/coldfire/GM/raw/master/meta/tieba_enhance.meta.js
// @downloadURL https://git.oschina.net/coldfire/GM/raw/master/tieba_enhance.user.js
// ==/UserScript==
+
"use strict";
var AddTail,
@@ -37,7 +38,9 @@ var AddTail,
open_setting_window,
tiebaData,
hasProp = {}.hasOwnProperty;
+
window.$ = window.jQuery = jQuery.noConflict(true);
+
tiebaData = {
StopPost: 0,
count: 0
@@ -48,32 +51,27 @@ log = function (msg) {
tiebaData.count += 1;
text = "hit " + tiebaData.count + " : " + msg;
return console.log(text);
-}; //setting win
-
+};
+//setting win
open_setting_window = function () {
var UpdateText, ref, ref1, x;
$('setting_shadow').remove();
- $('body').append(""); //读取设置
-
+ $('body').append("");
+ //读取设置
$("#fentie_date")[0].value = tiebaData.fentie_date;
-
if (!tiebaData.fentie_open) {
$("#fentie_open").attr("class", "setting_sp_btn close");
$("#fentie_open + div").css("display", "none");
}
-
if (!tiebaData.fentie_forbidden) {
$("#fentie_forbidden").attr("class", "setting_sp_btn close");
}
-
if (!tiebaData.tail_open) {
$("#tail_open").attr("class", "setting_sp_btn close");
$("#tail_select,#tail_select + div").css("display", "none");
}
-
ref = tiebaData.tail_data;
-
for (x in ref) {
if (!hasProp.call(ref, x)) continue;
$("#tail_select_text")[0].innerHTML = x;
@@ -83,17 +81,13 @@ open_setting_window = function () {
$("#tail_type_text")[0].innerHTML = tiebaData.tail_data[x].split("!分隔!")[1];
break;
}
-
ref1 = tiebaData.tail_data;
-
for (x in ref1) {
if (!hasProp.call(ref1, x)) continue;
$("#tail_option_box").append("" + x + "
");
}
-
UpdateText = function () {
var e;
-
if ($("#tail_type_text")[0].innerHTML === "javascript") {
try {
$("#tail_data_show")[0].innerHTML = eval($("#tail_data")[0].value);
@@ -107,7 +101,6 @@ open_setting_window = function () {
}
}
};
-
UpdateText();
$(".tail_option").click(function () {
$("#tail_select_text")[0].innerHTML = this.innerHTML;
@@ -124,15 +117,15 @@ open_setting_window = function () {
$("#tail_data").keyup(function () {
return UpdateText();
});
- $("#setting_shadow").fadeIn(400); //按钮
-
+ $("#setting_shadow").fadeIn(400);
+ //按钮
$("#setting_close").mouseenter(function () {
return this.innerHTML = "关闭";
});
$("#setting_close").mouseleave(function () {
return this.innerHTML = "设置";
- }); //$("#setting_window").click (e) -> e.stopPropagation()
-
+ });
+ //$("#setting_window").click (e) -> e.stopPropagation()
$("#setting_close").click(function () {
return $("#setting_shadow").fadeOut(400, function () {
return $("#setting_shadow").remove();
@@ -140,21 +133,17 @@ open_setting_window = function () {
});
$("#setting_reset").click(function () {
var j, key, len, ref2;
-
if (confirm("确定重置设置吗(会刷新页面)")) {
ref2 = GM_listValues();
-
for (j = 0, len = ref2.length; j < len; j++) {
key = ref2[j];
GM_deleteValue(key);
}
-
window.location.reload();
}
});
$("#fentie_open").click(function () {
$("#fentie_open + div").slideToggle("slow");
-
if (tiebaData.fentie_open) {
tiebaData.fentie_open = 0;
return $("#fentie_open").attr("class", "setting_sp_btn close");
@@ -217,13 +206,10 @@ open_setting_window = function () {
$("#tail_delete").click(function () {
var oname, ref2, ref3;
oname = $("#tail_select_text")[0].getAttribute("oname");
-
if ($("#tail_select_text")[0].getAttribute("new") !== 1) {
delete tiebaData.tail_data[oname];
}
-
ref2 = tiebaData.tail_data;
-
for (x in ref2) {
if (!hasProp.call(ref2, x)) continue;
$("#tail_select_text")[0].innerHTML = x;
@@ -232,27 +218,23 @@ open_setting_window = function () {
$("#tail_data")[0].value = tiebaData.tail_data[x].split("!分隔!")[0];
$("#tail_type_text")[0].innerHTML = tiebaData.tail_data[x].split("!分隔!")[1];
break;
- } //save
-
-
- GM_setValue("tail_data", JSON.stringify(tiebaData.tail_data)); //reload
-
+ }
+ //save
+ GM_setValue("tail_data", JSON.stringify(tiebaData.tail_data));
+ //reload
$("#tail_option_box").empty();
ref3 = tiebaData.tail_data;
-
for (x in ref3) {
if (!hasProp.call(ref3, x)) continue;
tiebaData.tail_data[x] = tiebaData.tail_data[x].replace(/!逗号!/g, ",").replace(/!引号!/g, "\"");
$("#tail_option_box").append("" + x + "
");
}
-
UpdateText();
});
$("#tail_save").click(function () {
var name, oname, ref2, ref3;
name = $("#tail_select_text")[0].innerHTML;
oname = $("#tail_select_text")[0].getAttribute("oname");
-
if ($("#tail_select_text")[0].getAttribute("new") === 1) {
if (tiebaData.tail_data[name] != null) {
return alert("该尾巴已存在!");
@@ -267,28 +249,23 @@ open_setting_window = function () {
tiebaData.tail_data[name] = $("#tail_data")[0].value + "!分隔!" + $("#tail_type_text")[0].textContent;
}
}
-
ref2 = tiebaData.tail_data;
-
for (x in ref2) {
if (!hasProp.call(ref2, x)) continue;
tiebaData.tail_data[x] = tiebaData.tail_data[x].replace(/,/g, "!逗号!").replace(/"/g, "!引号!");
}
-
- GM_setValue("tail_data", JSON.stringify(tiebaData.tail_data)); //reload
-
+ GM_setValue("tail_data", JSON.stringify(tiebaData.tail_data));
+ //reload
$("#tail_option_box").empty();
ref3 = tiebaData.tail_data;
-
for (x in ref3) {
if (!hasProp.call(ref3, x)) continue;
tiebaData.tail_data[x] = tiebaData.tail_data[x].replace(/!逗号!/g, ",").replace(/!引号!/g, "\"");
$("#tail_option_box").append("" + x + "
");
}
-
UpdateText();
- }); //保存部分
-
+ });
+ //保存部分
$("#setting_save").click(function () {
tiebaData.fentie_date = $("#fentie_date")[0].value;
GM_setValue("fentie_open", tiebaData.fentie_open);
@@ -299,71 +276,57 @@ open_setting_window = function () {
return $("#setting_shadow").remove();
});
});
-}; //坟贴检测函数
-
+};
+//坟贴检测函数
CheckPost = function () {
var date_str, date_time, days, years;
-
if ($("#j_core_title_wrap").length && tiebaData.fentie_open) {
date_str = $("#j_p_postlist ul.p_tail > li:nth-child(2) > span")[0].textContent;
-
if (date_str === "1970-01-01 07:00") {
return setTimeout(CheckPost, 500);
}
-
date_str = date_str.replace(" ", "-").replace(":", "-").split("-");
date_time = new Date(date_str[0], date_str[1] - 1, date_str[2], date_str[3], date_str[4]);
days = Math.round((new Date() - date_time) / 86400000);
-
if (days >= tiebaData.fentie_date) {
if (days >= 365) {
years = Math.round(days / 365);
- days = years + "\u5E74" + (days - years * 365);
+ days = `${years}年` + (days - years * 365);
}
-
- $("#tb_nav").after("\u8FD9\u662F\u4E00\u4E2A " + days + " \u5929\u7684\u575F\u8D34\u54E6~
");
-
+ $("#tb_nav").after(``);
if (tiebaData.fentie_forbidden) {
return tiebaData.StopPost = 1;
}
}
}
-}; //Tail
-
+};
+//Tail
AddTail = function (e) {
var currentTail, key, tailList;
-
if (tiebaData.StopPost === 1) {
if (!confirm("这可能是一个坟贴, 确认要回复么?")) {
return $("#ueditor_replace").empty();
}
}
-
if (tiebaData.tail_cur === "不使用小尾巴") {
return;
}
-
if (tiebaData.tail_cur === "随机小尾巴") {
tailList = function () {
var ref, results;
ref = tiebaData.tail_data;
results = [];
-
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
results.push(key);
}
-
return results;
}();
-
tiebaData.tail_cur = tailList[Math.round(Math.random() * tailList.length)];
}
-
currentTail = tiebaData.tail_data[tiebaData.tail_cur].split("!分隔!");
-
if (currentTail[1] === "html") {
$("#ueditor_replace").append(" " + currentTail[0]);
} else if (currentTail[1] === "javascript") {
@@ -373,11 +336,9 @@ AddTail = function (e) {
TailInit = function () {
var SendBt, i, ref, ref1, x;
-
if (!tiebaData.tail_open) {
return;
}
-
if (document.querySelector(".ui_btn.ui_btn_m.j_submit.poster_submit")) {
$("a.j_submit.poster_submit").before(" ");
$("#tail_use_text").click(function () {
@@ -388,38 +349,30 @@ TailInit = function () {
$("#tail_use_box").slideUp(400);
}
});
-
if (tiebaData.tail_cur === "不使用小尾巴" || tiebaData.tail_cur === "随机小尾巴") {
$("#tail_use_text")[0].innerHTML = tiebaData.tail_cur;
} else if (typeof tiebaData.tail_data[tiebaData.tail_cur] === "undefined") {
ref = tiebaData.tail_data;
-
for (i in ref) {
if (!hasProp.call(ref, i)) continue;
-
if (!(i != null)) {
continue;
}
-
tiebaData.tail_cur = i;
break;
}
-
GM_setValue("tail_cur", tiebaData.tail_cur);
$("#tail_use_text")[0].innerHTML = tiebaData.tail_cur;
} else {
$("#tail_use_text")[0].innerHTML = tiebaData.tail_cur;
}
-
$("#tail_use_box").append("不使用小尾巴
");
$("#tail_use_box").append("随机小尾巴
");
ref1 = tiebaData.tail_data;
-
for (x in ref1) {
if (!hasProp.call(ref1, x)) continue;
- $("#tail_use_box").append("" + x + "
");
+ $("#tail_use_box").append(`${x}
`);
}
-
$(".tail_use_option").click(function () {
tiebaData.tail_cur = this.innerHTML;
$("#tail_use_text")[0].innerHTML = tiebaData.tail_cur;
@@ -427,7 +380,6 @@ TailInit = function () {
});
SendBt = document.querySelector("a.j_submit.poster_submit[title=\"Ctrl+Enter快捷发表\"]");
SendBt.addEventListener("click", AddTail, true);
-
document.onkeydown = function (event) {
if (event.ctrlKey && event.keyCode === 13) {
return AddTail();
@@ -441,14 +393,11 @@ TailInit = function () {
clearLink = function (event) {
var link, ref, url;
link = event.target;
-
if (((ref = link.href) != null ? ref.indexOf("http://jump.bdimg.com/safecheck") : void 0) === 0) {
url = link.textContent;
-
if (url.indexOf("http") !== 0) {
url = "http://" + url;
}
-
return link.href = url;
}
};