更新(20191109)
This commit is contained in:
183
dev/js/index.js
Normal file
183
dev/js/index.js
Normal file
@@ -0,0 +1,183 @@
|
||||
/* ---- */
|
||||
/* 变量 */
|
||||
/* ---- */
|
||||
|
||||
// Slinky 插件的设置 //
|
||||
|
||||
var SlinkyOption = {
|
||||
title: true,
|
||||
speed: 200
|
||||
};
|
||||
|
||||
var ListID = "#list_"; // 列表 ID 前缀
|
||||
var ListCount = 0;
|
||||
var ListCountMax = 17; // 列表总数
|
||||
var FullsSreenText = document.getElementsByClassName("fullscreen-text")[0]; // 全屏文字
|
||||
|
||||
// main 中的 A 标签的对象的集合(链接列表)//
|
||||
|
||||
var LinkList = document.getElementsByTagName("main")[0].getElementsByTagName("a");
|
||||
|
||||
// 搜索面板 //
|
||||
|
||||
var SearchMode = 1;
|
||||
var SearchPanel = document.getElementsByClassName("search-panel")[0]; // 搜索面板
|
||||
var SearchInput = document.getElementsByClassName("search-input")[0]; // 搜索输入框
|
||||
var SearchResultTitle = document.getElementById("search-result-title"); // 搜索结果(标题)
|
||||
var SearchResultLink = document.getElementById("search-result-link"); // 搜索结果(链接)
|
||||
var SearchResultItem = "";
|
||||
|
||||
// 搜索引擎 //
|
||||
|
||||
var SearchEngineBaidu = document.getElementById("search-engine-baidu"); // 百度
|
||||
var SearchEngineBing = document.getElementById("search-engine-bing"); // Bing
|
||||
var SearchEngineGoogle = document.getElementById("search-engine-google"); // Google
|
||||
var SearchEnginebilibili = document.getElementById("search-engine-bilibili"); // bilibili
|
||||
|
||||
// 工具面板 //
|
||||
|
||||
var ToolPanel = document.getElementsByClassName("tool-panel")[0];
|
||||
|
||||
|
||||
/* ---- */
|
||||
/* 函数 */
|
||||
/* ---- */
|
||||
|
||||
// 查找字符 tChar 在 str 中第 num 次出现的位置 //
|
||||
|
||||
function findChar(str, tChar, num) {
|
||||
var charPos = str.indexOf(tChar);
|
||||
num = num - 1;
|
||||
if (num > 0) {
|
||||
for (var i = 0; i < num; i++) {
|
||||
charPos = str.indexOf(tChar, charPos + 1);
|
||||
}
|
||||
}
|
||||
return charPos;
|
||||
}
|
||||
|
||||
// 设置 target = "_blank" //
|
||||
|
||||
function setTarget() {
|
||||
for (var i = 0; i < LinkList.length; i++) {
|
||||
if (LinkList[i].href.endsWith("#") == false) {
|
||||
LinkList[i].target = "_blank";
|
||||
/* 自动加图标(暂不使用)
|
||||
var slashPos = findChar(LinkList[i].href, '/', 3);
|
||||
getFavicon = "https://www.google.cn/s2/favicons?domain=" + LinkList[i].href.substring(0, slashPos);
|
||||
var imgTag = "<img src='" + getFavicon + "' />";
|
||||
LinkList[i].insertAdjacentHTML("beforeBegin", imgTag);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 显示列表 //
|
||||
|
||||
function displayList() {
|
||||
document.getElementsByTagName("main")[0].style.opacity = "1";
|
||||
FullsSreenText.style.opacity = "0";
|
||||
setTimeout("document.getElementsByClassName('fullscreen-text')[0].style.display = 'none';", 1000);
|
||||
}
|
||||
|
||||
// 加载列表 //
|
||||
|
||||
function loadList() {
|
||||
ListCount = ListCount + 1;
|
||||
ListID = "#list_" + ListCount;
|
||||
$(ListID).slinky(SlinkyOption);
|
||||
FullsSreenText.innerText = "已加载 " + ListCount + " 个分类"; // 全屏文字
|
||||
// 加载完毕 //
|
||||
if (ListCount == ListCountMax) {
|
||||
clearInterval(I_LoadList); // 停止定时执行
|
||||
FullsSreenText.innerText = "加载完毕"; // 全屏文字
|
||||
setTarget(); // 设置 target
|
||||
displayList(); // 显示列表
|
||||
}
|
||||
}
|
||||
var I_LoadList = setInterval("loadList()", 100); // 加载列表,间隔 100 毫秒
|
||||
|
||||
// 搜索面板 //
|
||||
|
||||
function searchLink() {
|
||||
var LinkListCount = LinkList.length; // 循环次数
|
||||
var SearchWord = SearchInput.value.toLowerCase(); // 搜索关键词
|
||||
if (SearchMode == 1 && SearchWord != "") {
|
||||
SearchResultTitle.innerHTML = ""; // 清空搜索结果(标题)
|
||||
SearchResultLink.innerHTML = ""; // 清空搜索结果(链接)
|
||||
for (var i = 0; i < LinkListCount; i++) {
|
||||
// 排除 href 是 # 的元素 //
|
||||
if (LinkList[i].href.endsWith("#") == false) {
|
||||
// 匹配关键词 //
|
||||
if (LinkList[i].innerText.toLowerCase().indexOf(SearchWord) != -1) {
|
||||
// 匹配标题 //
|
||||
SearchResultItem = LinkList[i].cloneNode(true);
|
||||
SearchResultTitle.appendChild(SearchResultItem); // 复制元素
|
||||
} else if (LinkList[i].href.indexOf(SearchWord) != -1) {
|
||||
// 匹配链接 //
|
||||
SearchResultItem = LinkList[i].cloneNode(true);
|
||||
SearchResultLink.appendChild(SearchResultItem); // 复制元素
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (SearchMode == 1 && SearchWord == "") {
|
||||
SearchResultTitle.innerHTML = "";
|
||||
SearchResultLink.innerHTML = "未输入关键词";
|
||||
} else if (SearchMode == 2) {
|
||||
SearchInput.value = ""; // 清空输入框
|
||||
SearchResultTitle.innerHTML = ""; // 清空搜索结果(标题)
|
||||
SearchResultLink.innerHTML = ""; // 清空搜索结果(链接)
|
||||
SearchPanel.style.visibility = "hidden"; // 隐藏搜索面板
|
||||
} else {
|
||||
SearchResultTitle.innerHTML = "";
|
||||
SearchResultLink.innerHTML = "异常";
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索引擎 //
|
||||
|
||||
function searchWeb() {
|
||||
var GetSearchWord = document.getElementById("search-engine-input"); // 关键词输入框
|
||||
var SearchWord = GetSearchWord.value; // 关键词
|
||||
if (SearchEngineBaidu.checked == true) {
|
||||
window.open("https://www.baidu.com/s?ie=UTF-8&wd=" + SearchWord);
|
||||
} else if (SearchEngineBing.checked == true) {
|
||||
window.open("https://cn.bing.com/search?q=" + SearchWord);
|
||||
} else if (SearchEngineGoogle.checked == true) {
|
||||
window.open("https://www.google.com/search?q=" + SearchWord);
|
||||
} else if (SearchEnginebilibili.checked == true) {
|
||||
window.open("https://search.bilibili.com/all" + "?keyword=" + SearchWord);
|
||||
} else {
|
||||
GetSearchWord.value = "搜索引擎选择有误!"
|
||||
}
|
||||
}
|
||||
function setSearchEngine(Name) {
|
||||
switch (Name)
|
||||
{
|
||||
case "baidu":
|
||||
localStorage.setItem("SearchEngine", "baidu");
|
||||
break;
|
||||
case "bing":
|
||||
localStorage.setItem("SearchEngine", "bing");
|
||||
break;
|
||||
case "google":
|
||||
localStorage.setItem("SearchEngine", "google");
|
||||
break;
|
||||
case "bilibili":
|
||||
localStorage.setItem("SearchEngine", "bilibili");
|
||||
break;
|
||||
}
|
||||
}
|
||||
function getSearchEngine() {
|
||||
var SearchEngine = localStorage.getItem("SearchEngine");
|
||||
if (SearchEngine == "baidu") {
|
||||
SearchEngineBaidu.checked = true;
|
||||
} else if (SearchEngine == "bing") {
|
||||
SearchEngineBing.checked = true;
|
||||
} else if (SearchEngine == "google") {
|
||||
SearchEngineGoogle.checked = true;
|
||||
} else if (SearchEngine == "bilibili") {
|
||||
SearchEnginebilibili.checked = true;
|
||||
}
|
||||
}
|
||||
getSearchEngine();
|
4
dev/js/jquery-3.2.1.min.js
vendored
Normal file
4
dev/js/jquery-3.2.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
8
dev/js/slinky.min.js
vendored
Normal file
8
dev/js/slinky.min.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
!function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),e.exports=n(2)},function(e,t){function n(e,t){var n=Object.keys(e);return Object.getOwnPropertySymbols&&n.push.apply(n,Object.getOwnPropertySymbols(e)),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function s(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}
|
||||
/*
|
||||
* Slinky
|
||||
* Rather sweet menus
|
||||
* @author Ali Zahid <ali.zahid@live.com>
|
||||
* @license MIT
|
||||
*/
|
||||
var a=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.settings=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(r,!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({},this.options,{},r),this._init(t)}return s(e,[{key:"options",get:function(){return{resize:!0,speed:300,theme:"slinky-theme-default",title:!1}}}]),s(e,[{key:"_init",value:function(e){this.menu=jQuery(e),this.base=this.menu.children().first();var t=this.menu,n=this.settings;t.addClass("slinky-menu").addClass(n.theme),this._transition(n.speed),jQuery("a + ul",t).prev().addClass("next"),jQuery("li > a",t).wrapInner("<span>");var i=jQuery("<li>").addClass("header");jQuery("li > ul",t).prepend(i);var r=jQuery("<a>").prop("href","#").addClass("back");jQuery(".header",t).prepend(r),n.title&&jQuery("li > ul",t).each(function(e,t){var n=jQuery(t).parent().find("a").first().text();if(n){var i=jQuery("<header>").addClass("title").text(n);jQuery("> .header",t).append(i)}}),this._addListeners(),this._jumpToInitial()}},{key:"_addListeners",value:function(){var e=this,t=this.menu,n=this.settings;jQuery("a",t).on("click",function(i){if(e._clicked+n.speed>Date.now())return!1;e._clicked=Date.now();var r=jQuery(i.currentTarget);(0===r.attr("href").indexOf("#")||r.hasClass("next")||r.hasClass("back"))&&i.preventDefault(),r.hasClass("next")?(t.find(".active").removeClass("active"),r.next().show().addClass("active"),e._move(1),n.resize&&e._resize(r.next())):r.hasClass("back")&&(e._move(-1,function(){t.find(".active").removeClass("active"),r.parent().parent().hide().parentsUntil(t,"ul").first().addClass("active")}),n.resize&&e._resize(r.parent().parent().parentsUntil(t,"ul")))})}},{key:"_jumpToInitial",value:function(){var e=this.menu,t=this.settings,n=e.find(".active");n.length>0&&(n.removeClass("active"),this.jump(n,!1)),setTimeout(function(){return e.height(e.outerHeight())},t.speed)}},{key:"_move",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};if(0!==e){var n=this.settings,i=this.base,r=Math.round(parseInt(i.get(0).style.left))||0;i.css("left","".concat(r-100*e,"%")),"function"==typeof t&&setTimeout(t,n.speed)}}},{key:"_resize",value:function(e){this.menu.height(e.outerHeight())}},{key:"_transition",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:300,t=this.menu,n=this.base;t.css("transition-duration","".concat(e,"ms")),n.css("transition-duration","".concat(e,"ms"))}},{key:"jump",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(e){var n=this.menu,i=this.settings,r=jQuery(e),s=n.find(".active"),a=0;s.length>0&&(a=s.parentsUntil(n,"ul").length),n.find("ul").removeClass("active").hide();var o=r.parentsUntil(n,"ul");o.show(),r.show().addClass("active"),t||this._transition(0),this._move(o.length-a),i.resize&&this._resize(r),t||this._transition(i.speed)}}},{key:"home",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=this.base,n=this.menu,i=this.settings;e||this._transition(0);var r=n.find(".active"),s=r.parentsUntil(n,"ul");this._move(-s.length,function(){r.removeClass("active").hide(),s.not(t).hide()}),i.resize&&this._resize(t),!1===e&&this._transition(i.speed)}},{key:"destroy",value:function(){var e=this,t=this.base,n=this.menu;jQuery(".header",n).remove(),jQuery("a",n).removeClass("next").off("click"),n.css({height:"","transition-duration":""}),t.css({left:"","transition-duration":""}),jQuery("li > a > span",n).contents().unwrap(),n.find(".active").removeClass("active"),n.attr("class").split(" ").forEach(function(e){0===e.indexOf("slinky")&&n.removeClass(e)});["settings","menu","base"].forEach(function(t){return delete e[t]})}}]),e}();jQuery.fn.slinky=function(e){return new a(this,e)}},function(e,t,n){}]);
|
302
dev/js/tool.js
Normal file
302
dev/js/tool.js
Normal file
@@ -0,0 +1,302 @@
|
||||
/* --------------- */
|
||||
/* Unix 时间戳转换 */
|
||||
/* --------------- */
|
||||
|
||||
// 函数:将传入的时间转换为时间戳 //
|
||||
function toolUnixTimeToUnix(GetTime, isMillisecond) {
|
||||
var Time = new Date(); // 创建 Date 对象
|
||||
// 根据 GetTime 设置时间 //
|
||||
Time.setFullYear(GetTime.substring(0, 4)); // GetTime 的子串:年
|
||||
Time.setMonth(GetTime.substring(5, 7) - 1); // GetTime 的子串:月
|
||||
Time.setDate(GetTime.substring(8, 10)); // GetTime 的子串:日
|
||||
Time.setHours(GetTime.substring(11, 13)); // GetTime 的子串:时
|
||||
Time.setMinutes(GetTime.substring(14, 16)); // GetTime 的子串:分
|
||||
Time.setSeconds(GetTime.substring(17, 19)); // GetTime 的子串:秒
|
||||
// 调试 //
|
||||
// console.log("时间:" + Time);
|
||||
// 根据 isMillisecond 确认输出的单位
|
||||
if (isMillisecond == false) {
|
||||
// 模式:秒 //
|
||||
var TextLength = Time.getTime().toString().length; // 获取字符串长度
|
||||
return Time.getTime().toString().substring(0, TextLength - 3); // 返回时间戳
|
||||
} else if (isMillisecond == true) {
|
||||
// 模式:毫秒 //
|
||||
var TextLength = Time.getTime().toString().length; // 获取字符串长度
|
||||
return Time.getTime().toString().substring(0, TextLength - 3) + "000"; // 返回时间戳
|
||||
} else {
|
||||
return "模式有误!";
|
||||
}
|
||||
}
|
||||
|
||||
// 函数:将传入的时间戳转换为时间 //
|
||||
function toolUnixTimeToTime(GetUnix, isMillisecond) {
|
||||
var Time = new Date(); // 创建 Date 对象
|
||||
// 根据 isMillisecond 确认输入的单位
|
||||
if (isMillisecond == false) {
|
||||
// 模式:秒 //
|
||||
GetUnix = GetUnix + "000"; // 补零变为毫秒
|
||||
Time.setTime(GetUnix); // 根据 GetUnix 设置时间
|
||||
} else if (isMillisecond == true) {
|
||||
// 模式:毫秒 //
|
||||
Time.setTime(GetUnix); // 根据 GetUnix 设置时间
|
||||
} else {
|
||||
Time.setTime("0"); // 把时间设置为 0
|
||||
}
|
||||
var TimeYear = Time.getFullYear(); // 年
|
||||
var TimeMonth = Time.getMonth() + 1; // 月
|
||||
// 补零 //
|
||||
if (TimeMonth.toString().length == 1) {
|
||||
TimeMonth = "0" + TimeMonth;
|
||||
}
|
||||
var TimeDate = Time.getDate(); // 日
|
||||
// 补零 //
|
||||
if (TimeDate.toString().length == 1) {
|
||||
TimeDate = "0" + TimeDate;
|
||||
}
|
||||
var TimeHour = Time.getHours(); // 时
|
||||
// 补零 //
|
||||
if (TimeHour.toString().length == 1) {
|
||||
TimeHour = "0" + TimeHour;
|
||||
}
|
||||
var TimeMinute = Time.getMinutes(); // 分
|
||||
// 补零 //
|
||||
if (TimeMinute.toString().length == 1) {
|
||||
TimeMinute = "0" + TimeMinute;
|
||||
}
|
||||
var TimeSecond = Time.getSeconds(); // 秒
|
||||
// 补零 //
|
||||
if (TimeSecond.toString().length == 1) {
|
||||
TimeSecond = "0" + TimeSecond;
|
||||
}
|
||||
// 返回:年-月-日 时:分:秒 //
|
||||
return TimeYear + "-" + TimeMonth + "-" + TimeDate + " " + TimeHour + ":" + TimeMinute + ":" + TimeSecond;
|
||||
}
|
||||
|
||||
// 按钮:当前 //
|
||||
function toolUnixTimeNow() {
|
||||
var GetInputA = document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0]; // 输入框 A
|
||||
var GetInputB = document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0]; // 输入框 B
|
||||
var GetSettingAA = document.getElementById("unixtime-setting-aa").checked; // A 模式:秒
|
||||
var GetSettingAB = document.getElementById("unixtime-setting-ab").checked; // A 模式:毫秒
|
||||
var GetSettingBA = document.getElementById("unixtime-setting-ba").checked; // B 模式:秒
|
||||
var GetSettingBB = document.getElementById("unixtime-setting-bb").checked; // B 模式:毫秒
|
||||
// 调用函数,获取时间 //
|
||||
if (GetSettingAA == true) {
|
||||
var Time = new Date(); // 创建 Date 对象
|
||||
var TextLength = Time.getTime().toString().length; // 获取字符串长度
|
||||
GetInputA.value = Time.getTime().toString().substring(0, TextLength - 3); // 时间戳(秒)
|
||||
} else if (GetSettingAB == true) {
|
||||
GetInputA.value = new Date().getTime(); // 时间戳(毫秒)
|
||||
}
|
||||
GetInputB.value = toolUnixTimeToTime(new Date().getTime(), true); // 时间
|
||||
}
|
||||
|
||||
// 按钮:转换 //
|
||||
function toolUnixTimeSubmit() {
|
||||
var GetInputA = document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0]; // 输入框 A
|
||||
var GetInputB = document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0]; // 输入框 B
|
||||
var GetOutputA = document.getElementById("tool-unixtime-output-a").getElementsByTagName("input")[0]; // 输出框 A
|
||||
var GetOutputB = document.getElementById("tool-unixtime-output-b").getElementsByTagName("input")[0]; // 输出框 B
|
||||
var GetSettingAA = document.getElementById("unixtime-setting-aa").checked; // A 模式:秒
|
||||
var GetSettingAB = document.getElementById("unixtime-setting-ab").checked; // A 模式:毫秒
|
||||
var GetSettingBA = document.getElementById("unixtime-setting-ba").checked; // B 模式:秒
|
||||
var GetSettingBB = document.getElementById("unixtime-setting-bb").checked; // B 模式:毫秒
|
||||
// 调用函数,转换时间 //
|
||||
if (GetSettingAA == true) {
|
||||
// 秒 //
|
||||
GetOutputA.value = toolUnixTimeToTime(GetInputA.value, false); // 转换为时间
|
||||
} else if (GetSettingAB == true) {
|
||||
// 毫秒 //
|
||||
GetOutputA.value = toolUnixTimeToTime(GetInputA.value, GetSettingAB); // 转换为时间
|
||||
}
|
||||
GetOutputB.value = toolUnixTimeToUnix(GetInputB.value, GetSettingBB); // 转换为时间戳
|
||||
}
|
||||
|
||||
// 按钮:重置 //
|
||||
function toolUnixTimeClear() {
|
||||
document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0].value = ''; // 清空输入框 A
|
||||
document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0].value = ''; // 清空输入框 B
|
||||
document.getElementById("tool-unixtime-output-a").getElementsByTagName("input")[0].value = ''; // 清空输出框 A
|
||||
document.getElementById("tool-unixtime-output-b").getElementsByTagName("input")[0].value = ''; // 清空输出框 B
|
||||
}
|
||||
|
||||
/* ---- */
|
||||
/* 计算 */
|
||||
/* ---- */
|
||||
|
||||
function toolCalculateSubmit() {
|
||||
GetInput = document.getElementById("tool-calculate-input"); // 算式输入框
|
||||
GetToFixed = document.getElementById("tool-calculate-tofixed"); // 保留小数点后的位数
|
||||
GetResult = document.getElementById("tool-calculate-result").getElementsByTagName("span")[0]; // 结果
|
||||
GetCal = GetInput.value; // 获取输入的算式
|
||||
GetCal = GetCal.replace(/π/g, "Math.PI"); // 替换(圆周率,Math.PI)
|
||||
GetCal = GetCal.replace(/幂/g, "Math.pow"); // 替换(乘方运算,Math.pow)
|
||||
GetCal = GetCal.replace(/平方根/g, "Math.sqrt"); // 替换(乘方运算,Math.pow)
|
||||
// 运行 //
|
||||
if (GetToFixed.value >= 0 && GetToFixed.value <= 16) {
|
||||
GetResult.innerText = eval(GetCal).toFixed(GetToFixed.value);
|
||||
} else {
|
||||
GetResult.innerText = "保留位数有误(0 ~ 16 之间)";
|
||||
}
|
||||
}
|
||||
|
||||
function toolCalculateClear() {
|
||||
GetInput = document.getElementById("tool-calculate-input"); // 算式输入框
|
||||
GetInput.value = ''; // 清空“输入框”和“结果”
|
||||
GetResult.innerText = ''; // 清空“结果”
|
||||
}
|
||||
|
||||
/* ---------------- */
|
||||
/* 生成批量下载链接 */
|
||||
/* ---------------- */
|
||||
|
||||
function toolGenLinkSubmit() {
|
||||
var VarText = "(*)"; // 变量表示
|
||||
var BaseLink = document.getElementById("tool-genlink-link").getElementsByTagName("input")[0].value; // 网址
|
||||
var GetSettingType = document.getElementsByName("genlink-settings"); // 批量变化类型
|
||||
// 设定 //
|
||||
var GetSettingA = document.getElementById("tool-genlink-settings-a").getElementsByTagName("input"); // 等差数列
|
||||
var GetSettingB = document.getElementById("tool-genlink-settings-b").getElementsByTagName("input"); // 等比数列
|
||||
var GetSettingC = document.getElementById("tool-genlink-settings-c").getElementsByTagName("input"); // 字母变化
|
||||
// 结果 //
|
||||
var GetResult = document.getElementById("tool-genlink-result");
|
||||
var LinkReplace = '';
|
||||
var LinkResult = '';
|
||||
// 自动补零 //
|
||||
function AddZero() {
|
||||
if (NumLength < NumLastLength) {
|
||||
var ZeroMax = NumLastLength - NumLength; // 自动补零的个数
|
||||
// 自动补 0 //
|
||||
for (let i = 1; i <= ZeroMax; i++) {
|
||||
Num = "0" + Num;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 替换变量;替换变量;判断是否开启倒序;拼接结果;拼接结果 //
|
||||
function CheckReverse() {
|
||||
LinkReplace = BaseLink.replace(VarText, Num); // 替换链接中的变量为当前值(VarText 替换为 Num)
|
||||
if (GetReverse == false) {
|
||||
// console.log("非倒序");
|
||||
LinkResult = LinkResult + LinkReplace + "\n"; // 拼接结果
|
||||
} else if (GetReverse == true) {
|
||||
// console.log("倒序");
|
||||
LinkResult = LinkReplace + "\n" + LinkResult; // 拼接结果
|
||||
}
|
||||
}
|
||||
// 运行 //
|
||||
if (GetSettingType[0].checked == true) {
|
||||
// 等差数列 //
|
||||
// console.log("等差数列");
|
||||
var GetFirst = parseInt(GetSettingA[1].value); // 首项
|
||||
var GetLength = parseInt(GetSettingA[2].value); // 项数
|
||||
var GetDiff = parseInt(GetSettingA[3].value); // 公差
|
||||
var GetZero = GetSettingA[4].checked; // 补零
|
||||
var GetReverse = GetSettingA[5].checked; // 倒序
|
||||
// 判断是否开启补零 //
|
||||
if (GetZero == true) {
|
||||
// 等差数列 补零 //
|
||||
// console.log("等差数列 补零");
|
||||
var Num; // 当前项的值
|
||||
var NumLength; // 当前项的值的位数
|
||||
var NumLast = GetFirst + (GetLength - 1) * GetDiff; // 根据等差数列通项公式计算末项的值
|
||||
var NumLastLength = NumLast.toString().length; // 末项的值的位数
|
||||
// console.log("末项的值:" + NumLast);
|
||||
for (var i = 1; i <= GetLength; i++) {
|
||||
Num = GetFirst + (i - 1) * GetDiff; // 根据等差数列通项公式计算当前项的值
|
||||
NumLength = Num.toString().length; // 当前项的值的位数
|
||||
AddZero(); // 若位数不足,自动补零
|
||||
CheckReverse(); // 替换变量;判断是否开启倒序;拼接结果
|
||||
}
|
||||
} else if (GetZero == false) {
|
||||
// 等差数列 不补零 //
|
||||
// console.log("等差数列 不补零");
|
||||
var Num; // 当前项的值
|
||||
for (var i = 1; i <= GetLength; i++) {
|
||||
Num = GetFirst + (i - 1) * GetDiff; // 根据等差数列通项公式计算当前项的值
|
||||
CheckReverse(); // 替换变量;判断是否开启倒序;拼接结果
|
||||
}
|
||||
}
|
||||
} else if (GetSettingType[1].checked == true) {
|
||||
// 等比数列 //
|
||||
var GetFirst = parseInt(GetSettingB[1].value); // 首项
|
||||
var GetLength = parseInt(GetSettingB[2].value); // 项数
|
||||
var GetDiff = parseInt(GetSettingB[3].value); // 公比
|
||||
var GetZero = GetSettingB[4].checked; // 补零
|
||||
var GetReverse = GetSettingB[5].checked; // 倒序
|
||||
// 判断是否开启补零 //
|
||||
if (GetZero == true) {
|
||||
// 等比数列 补零 //
|
||||
// console.log("等比数列 补零");
|
||||
var Num; // 当前项的值
|
||||
var NumLength; // 当前项的值的位数
|
||||
var NumLast = GetFirst * Math.pow(GetDiff, (GetLength - 1)); // 根据等比数列通项公式计算末项的值
|
||||
var NumLastLength = NumLast.toString().length; // 末项的值的位数
|
||||
// console.log("末项的值:" + NumLast);
|
||||
for (var i = 1; i <= GetLength; i++) {
|
||||
Num = GetFirst * Math.pow(GetDiff, (i - 1)); // 根据等比数列通项公式计算当前项的值
|
||||
NumLength = Num.toString().length; // 当前项的值的位数
|
||||
AddZero(); // 若位数不足,自动补零
|
||||
CheckReverse(); // 替换变量;判断是否开启倒序;拼接结果
|
||||
}
|
||||
} else if (GetZero == false) {
|
||||
// 等比数列 不补零 //
|
||||
// console.log("等比数列 不补零");
|
||||
var Num; // 当前项的值
|
||||
for (var i = 1; i <= GetLength; i++) {
|
||||
Num = GetFirst * Math.pow(GetDiff, (i - 1)); // 根据等比数列通项公式计算当前项的值
|
||||
CheckReverse(); // 替换变量;判断是否开启倒序;拼接结果
|
||||
}
|
||||
}
|
||||
} else if (GetSettingType[2].checked == true) {
|
||||
// 字母变化 //
|
||||
var GetFirst = GetSettingC[1].value.charCodeAt(0); // 从(获取对应字母的 Unicode 编码)
|
||||
var GetLast = GetSettingC[2].value.charCodeAt(0); // 到(获取对应字母的 Unicode 编码)
|
||||
var GetReverse = GetSettingC[3].checked; // 倒序
|
||||
// console.log("从:" + GetFirst);
|
||||
// console.log("到:" + GetLast);
|
||||
// console.log("倒序:" + GetReverse);
|
||||
if (GetFirst >= 65 && GetFirst <= 122 && GetLast >= 65 && GetLast <= 122) {
|
||||
if (GetFirst < GetLast) {
|
||||
for (var i = GetFirst; i <= GetLast; i++) {
|
||||
if (i >= 91 && i <= 96) {
|
||||
continue; // 若为 [ \ ] ^ _ ` 则跳出循环
|
||||
}
|
||||
Num = String.fromCharCode(i); // 获取对应 Unicode 编码的字母
|
||||
CheckReverse(); // 替换变量;判断是否开启倒序;拼接结果
|
||||
}
|
||||
} else if (GetFirst > GetLast) {
|
||||
GetResult.placeholder = "字母先后顺序有误。\n请按此顺序填写:\nA - Z a - z\n例如:\n从 a 到 d\n从 A 到 D\n从 X 到 g";
|
||||
} else if (GetFirst == GetLast) {
|
||||
GetResult.placeholder = "仅有 1 条链接,无需生成。";
|
||||
} else {
|
||||
GetResult.placeholder = "异常。";
|
||||
}
|
||||
} else {
|
||||
GetResult.placeholder = "超出范围。";
|
||||
}
|
||||
} else {
|
||||
// 异常 //
|
||||
GetResult.placeholder = "类型选择有误";
|
||||
}
|
||||
GetResult.value = LinkResult; // 输出批量结果
|
||||
}
|
||||
|
||||
function toolGenLinkClear() {
|
||||
var GetResult = document.getElementById("tool-genlink-result");
|
||||
GetResult.value = ''; // 清空结果
|
||||
GetResult.placeholder = "结果";
|
||||
}
|
||||
|
||||
/* --------------- */
|
||||
/* 运行 JavaScript */
|
||||
/* --------------- */
|
||||
|
||||
function toolRunJSSubmit() {
|
||||
GetCode = document.getElementById("tool-runjs-input"); // 代码输入框
|
||||
eval(GetCode.value); // 运行
|
||||
}
|
||||
|
||||
function toolRunJSClear() {
|
||||
GetCode = document.getElementById("tool-runjs-input"); // 代码输入框
|
||||
GetCode.value = ''; // 清空
|
||||
}
|
Reference in New Issue
Block a user