// ==UserScript== // @name hipda-ID笔记 // @namespace http://tampermonkey.net/ // @version 0.4.0 // @description 来自地板带着爱,记录上网冲浪的美好瞬间 // @author 屋大维 // @license MIT // @match https://www.hi-pda.com/forum/* // @resource IMPORTED_CSS https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css // @require https://code.jquery.com/jquery-3.4.1.min.js // @require https://code.jquery.com/ui/1.13.0/jquery-ui.js // @icon https://icons.iconarchive.com/icons/iconshock/real-vista-project-managment/64/task-notes-icon.png // @grant GM.setValue // @grant GM.getValue // @grant GM.deleteValue // @grant GM_getResourceText // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function() { 'use strict'; // CONST const BROWSER_KEY = 'alt+I'; const MANAGEMENT_KEY = "alt+U"; // CSS const my_css = GM_getResourceText("IMPORTED_CSS"); GM_addStyle(my_css); GM_addStyle(".no-close .ui-dialog-titlebar-close{display:none} textarea{height:100%;width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} .card{box-shadow:0 4px 8px 0 rgba(0,0,0,.2);transition:.3s;width:100%;overflow-y: scroll;}.card:hover{box-shadow:0 8px 16px 0 rgba(0,0,0,.2)}.container{padding:2px 16px}"); GM_addStyle(".flex-container{display:flex;flex-wrap: wrap;}.flex-container>div{background-color:#f1f1f1;width:500px;max-height:500px;margin:15px; padding:5px;text-align:left;}"); // Your code here... // helpers function getKeys(e){ // keycode 转换 var codetable={'96':'Numpad 0','97':'Numpad 1','98':'Numpad 2','99':'Numpad 3','100':'Numpad 4','101':'Numpad 5','102':'Numpad 6','103':'Numpad 7','104':'Numpad 8','105':'Numpad 9','106':'Numpad *','107':'Numpad +','108':'Numpad Enter','109':'Numpad -','110':'Numpad .','111':'Numpad /','112':'F1','113':'F2','114':'F3','115':'F4','116':'F5','117':'F6','118':'F7','119':'F8','120':'F9','121':'F10','122':'F11','123':'F12','8':'BackSpace','9':'Tab','12':'Clear','13':'Enter','16':'Shift','17':'Ctrl','18':'Alt','20':'Cape Lock','27':'Esc','32':'Spacebar','33':'Page Up','34':'Page Down','35':'End','36':'Home','37':'←','38':'↑','39':'→','40':'↓','45':'Insert','46':'Delete','144':'Num Lock','186':';:','187':'=+','188':',<','189':'-_','190':'.>','191':'/?','192':'`~','219':'[{','220':'\|','221':']}','222':'"'}; var Keys = ''; e.shiftKey && (e.keyCode != 16) && (Keys += 'shift+'); e.ctrlKey && (e.keyCode != 17) && (Keys += 'ctrl+'); e.altKey && (e.keyCode != 18) && (Keys += 'alt+'); return Keys + (codetable[e.keyCode] || String.fromCharCode(e.keyCode) || ''); }; function addHotKey(codes,func){// 监视并执行快捷键对应的函数 document.addEventListener('keydown', function(e){ if ((e.target.tagName != 'INPUT') && (e.target.tagName != 'TEXTAREA') && getKeys(e) == codes){ func(); e.preventDefault(); e.stopPropagation(); } }, false); }; function htmlToElement(html) { var template = document.createElement('template'); html = html.trim(); // Never return a text node of whitespace as the result template.innerHTML = html; return template.content.firstChild; } function getEpoch(date_str, time_str) { let [y, m, d] = date_str.split("-").map(x => parseInt(x)); let [H, M] = time_str.split(":").map(x => parseInt(x)); return new Date(y, m-1, d, H, M, 0).getTime() / 1000; } // classes class HpThread { constructor() { } getThreadTid() { return location.href.match(/tid=(\d+)/) ? parseInt(location.href.match(/tid=(\d+)/)[1]) : -999; } getUserUid() { return parseInt($("cite > a").attr("href").split("uid=")[1]); } getThreadTitle() { let l = $('#nav').text().split(" » "); return l[l.length - 1]; } getHpPosts() { let threadTid = this.getThreadTid(); let threadTitle = this.getThreadTitle(); let divs = $('#postlist > div').get(); return divs.map(d => new HpPost(threadTid, threadTitle, d)); } addNoteBrowserUI(_notebook) { $('#menu>ul').append($(``)); var that = this; // create dialog let dialog = htmlToElement(` `); $("body").append(dialog); function updateNoteList() { $('#noteDialog_browser_note_list').empty(); // remove all notes from the list var notes; var searchMethod = $('#noteDialog_browser_search_method').val(); var searchInput = $('#noteDialog_browser_search_input').val(); if (searchMethod === "userName") { notes = _notebook.getNotesByUsername(searchInput); } else if (searchMethod === "content") { notes = _notebook.getNotesByKeyword(searchInput); } else { return; } for (let i=0; i$&'); } if (searchMethod === 'content') { content = content.replaceAll(searchInput, '$&'); } // highlight all URLs var expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; var regex = new RegExp(expression); content = content.replace(regex, '$&') var html = `
${userName}
${content}
`; var element = $(html); // delete element.find("button.noteDeleteButton").click(function() { let r = confirm(`确定要删除 ${note.userName} 的ID笔记吗?`); if (!r) { return; } _notebook.delete(uid); updateNoteList(); }); // edit element.find("button.noteEditButton").click(function() { // note dialog (this will be different from the one opened in posts) let dialog = htmlToElement(`