// ==UserScript== // @name hipda-ID笔记 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 来自地板带着爱,记录上网冲浪的美好瞬间 // @author 屋大维 // @license MIT // @match https://www.hi-pda.com/forum/* // @match https://www.4d4y.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 // @grant GM.xmlHttpRequest // @downloadURL none // ==/UserScript== (function() { 'use strict'; // CONST const SERVER_ENDPOINT = 'https://hp-notebook-server.hi-python.com'; 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;}"); GM_addStyle(`.lds-roller{display:inline-block;position:fixed;top:50vh;left:50vh;width:80px;height:80px}.lds-roller div{animation:1.2s cubic-bezier(.5,0,.5,1) infinite lds-roller;transform-origin:40px 40px}.lds-roller div:after{content:" ";display:block;position:absolute;width:7px;height:7px;border-radius:50%;background:#bfa1cf;margin:-4px 0 0 -4px}.lds-roller div:first-child{animation-delay:-36ms}.lds-roller div:first-child:after{top:63px;left:63px}.lds-roller div:nth-child(2){animation-delay:-72ms}.lds-roller div:nth-child(2):after{top:68px;left:56px}.lds-roller div:nth-child(3){animation-delay:-108ms}.lds-roller div:nth-child(3):after{top:71px;left:48px}.lds-roller div:nth-child(4){animation-delay:-144ms}.lds-roller div:nth-child(4):after{top:72px;left:40px}.lds-roller div:nth-child(5){animation-delay:-.18s}.lds-roller div:nth-child(5):after{top:71px;left:32px}.lds-roller div:nth-child(6){animation-delay:-216ms}.lds-roller div:nth-child(6):after{top:68px;left:24px}.lds-roller div:nth-child(7){animation-delay:-252ms}.lds-roller div:nth-child(7):after{top:63px;left:17px}.lds-roller div:nth-child(8){animation-delay:-288ms}.lds-roller div:nth-child(8):after{top:56px;left:12px}@keyframes lds-roller{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}`); // Your code here... // helpers function showLoader() { let loader = $(`
`); $("body").append(loader); } function hideLoader() { $(".lds-roller").remove(); } 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; } console.log(notes.length) for (let i = 0; i < notes.length; i++) { let element = noteToHtmlElement(notes[i]); $('#noteDialog_browser_note_list').append(element); } } function noteToHtmlElement(note) { var searchMethod = $('#noteDialog_browser_search_method').val(); var searchInput = $('#noteDialog_browser_search_input').val(); var userName = note.userName; var uid = note.uid; var content = note.note; if (searchMethod === 'userName') { userName = userName.replaceAll(searchInput, '$&'); } 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(`