| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1834 人关注过本帖
标题:论坛代码运行字号和字体修改脚本
只看楼主 加入收藏
xyzdwf
Rank: 2
等 级:论坛游民
威 望:1
帖 子:52
专家分:10
注 册:2017-1-9
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:4 
论坛代码运行字号和字体修改脚本
编程论坛运行代码(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地址:
https://
收到的鲜花
  • 静夜思2021-09-16 16:38 送鲜花  10朵   附言:高手👍
搜索更多相关主题的帖子: value editor var style function 
2021-09-16 13:54
xyzdwf
Rank: 2
等 级:论坛游民
威 望:1
帖 子:52
专家分:10
注 册:2017-1-9
收藏
得分:0 
已测试OrangeMonkey和TamperMonkey使用正常
图片附件: 游客没有浏览图片的权限,请 登录注册
2021-09-16 14:00
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1508
专家分:9241
注 册:2010-3-16
收藏
得分:10 
2021-09-16 22:55
幻紫灵心
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:山咔咔里面
等 级:贵宾
威 望:53
帖 子:396
专家分:2640
注 册:2018-3-30
收藏
得分:10 

saber,别哭.
2021-09-17 09:20
xyzdwf
Rank: 2
等 级:论坛游民
威 望:1
帖 子:52
专家分:10
注 册:2017-1-9
收藏
得分:0 
感谢支持,趁着热乎更新下,加入代码区域宽度调整后保存
程序代码:
// ==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.addEventListener("load", function() {
        on_window_loaded();
    });

})();

var cfontsz = null;
var cfontfm = null;
var cleftw = null;
var crightw = 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);

    //restore code area width, console area width 
    cleftw = GM_getValue('cleft_width');
    crightw = GM_getValue('cright_width');
    if ($AVA(cleftw) && $AVA(crightw)) {
        var la = $Q("#wrapper>.left");
        var ra = $Q("#wrapper>.right");
        la.style.width = cleftw;
        ra.style.width = crightw;
    }
    add_cawc_listener();
}

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);
}

/** add code area width change listener */
var cawc_flag = 0;
function add_cawc_listener() {
    $Q("#wrapper>.middle").addEventListener("mousedown",
    function() {
        cawc_flag = 1;
    });
    document.body.addEventListener("mouseup",
    function() {
        if (cawc_flag) {
            var la = $Q("#wrapper>.left");
            var ra = $Q("#wrapper>.right");
            cleftw = la.style.width;
            crightw = ra.style.width;
            GM_setValue('cleft_width', cleftw);
            GM_setValue('cright_width', crightw);
        }
        cawc_flag = 0;
    });
}
2021-09-17 11:34
快速回复:论坛代码运行字号和字体修改脚本
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026243 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved