论坛代码运行字号和字体修改脚本
编程论坛运行代码(https://www.bccn.net/run/?lang=c)字号,字体修改,并保存设置值到脚本上下文中,下次会自动加载程序代码:
// ==UserScript== // @name bccn_net_run_code_style // @namespace bccn_net_run_code/style // @version 0.1 // @description 编程论坛运行代码字号字体修改,change bccn.net run code style // @author xyz // @match *://*.bccn.net/run* // @icon data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAASABIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDX1LxBDZavJHcXN/LIrard3ER1W9iaVI5rkQxwiKTamBAdxKhQuOcnFS6fe6jcalab9E1qaxvp4I4xb6rrKvao335JHkVUdR1+Urj3HIXV9AvNS0zUL2xsdTubhV1m3R0lhMEIa5uS2yNg0hlfCxnYoyr43DFcvY+BPEGk+I/DtxNooCNqttNvtrIkpGs8jMXZWbywFaM4bHG0f8s2r6ilTw86bvKz10v6vo1b+uhg27nuHg+ea68E6BcXEryzS6dbvJJIxZnYxqSSTyST3oqPwR/yIPhz/sF23/opaK+bq/xJerNlsST+D/DF1cSXFx4c0iWaVy8kkljEzOxOSSSuSSe9R/8ACEeE/wDoV9F/8F8X/wATRRXuQ+FGZtQQQ2tvHb28SRQxIEjjjUKqKBgAAcAAdqKKK8GfxM1P/9k= // @grant GM_setValue // @grant GM_getValue // ==/UserScript== function $A(a, b) { b.appendChild(a); } function $B(a, b) { b.parentNode.insertBefore(a, b); } function $C(a) { return document.createElement(a); } function $Q(a) { return document.querySelector(a); } function $QA(a) { return document.querySelectorAll(a); } function $AVA(a) { return a!=null || typeof(a)!='undefined'; } (function() { 'use strict'; window.onload = on_window_loaded; })(); var cfontsz = null; var cfontfm = null; function on_window_loaded(){ cfontsz = GM_getValue('cfont_size'); cfontfm = GM_getValue('cfont_family'); var editor = $Q("#wrapper>.left>#editor"); var run_btn = $Q("#wrapper>.toolbar>#button_run"); run_btn.style.marginLeft="10px"; //font size var fz_lbl = $C("span"); fz_lbl.innerHTML="字号 "; fz_lbl.style.marginLeft="10px"; var fz_sel = $C("select"); var fz_ava = $AVA(cfontsz); for(var i=10; i<21; i++){ var fz_opt = $C("option"); fz_opt.value = i; fz_opt.innerHTML=i; if(fz_ava && cfontsz == i){ fz_opt.selected = 1; editor.style.fontSize = cfontsz+"px"; } $A(fz_opt, fz_sel); } fz_sel.onchange=on_fz_sel_change; $B(fz_lbl, run_btn); $B(fz_sel, run_btn); //font family var fm_lbl = $C("span"); fm_lbl.innerHTML="字体 "; fm_lbl.style.marginLeft="10px"; var fm_sel = $C("select"); var fm_ava = $AVA(cfontfm); var fm_arr =['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Droid Sans Mono', 'Courier']; for(var i=0; i<fm_arr.length; i++){ var fm_opt = $C("option"); fm_opt.value = fm_arr[i]; fm_opt.innerHTML=fm_arr[i]; if(fm_ava && cfontfm == fm_arr[i]){ fm_opt.selected = 1; editor.style.fontFamily = cfontfm; } $A(fm_opt, fm_sel); } fm_sel.onchange=on_fm_sel_change; $B(fm_lbl, run_btn); $B(fm_sel, run_btn); } function on_fz_sel_change(){ var editor = $Q("#wrapper>.left>#editor"); editor.style.fontSize = this.value+"px"; cfontsz = this.value; GM_setValue('cfont_size', cfontsz); } function on_fm_sel_change(){ var editor = $Q("#wrapper>.left>#editor"); editor.style.fontFamily = this.value; cfontfm = this.value; GM_setValue('cfont_family', cfontfm); }
greasyfork地址:
" target="_blank">https://