// ==UserScript== // @name 北邮人论坛 - 变好看! // @namespace http://github.com/Maxlinn/ // @version 3.2.0 // @description 一些仅在前端的北邮人论坛美化 // @author Maxlinn // @match https://bbs.byr.cn/ // @icon https://bbs.byr.cn/favicon.ico // @homepageURL https://github.com/Maxlinn/byrbbs-modern-frontend // @supportURL https://github.com/Maxlinn/byrbbs-modern-frontend // @updateURL https://raw.githubusercontent.com/Maxlinn/byrbbs-modern-frontend/master/main.user.js // @downloadURL https://raw.githubusercontent.com/Maxlinn/byrbbs-modern-frontend/master/main.user.js // // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js // @grant none // ==/UserScript== // ***********************************设置用变量************************************* // 论坛全文搜索API,由校友提供,不保证可靠性 var fulltext_search_api = "http://oneseven.cc/byrbbs/?key="; // 论坛各组件的字体 var widget_font = `Verdana, Tahoma, Arial, "Microsoft YaHei", "Hiragino Sans GB", "WenQuanYi Micro Hei", sans-serif`; // 阅读文章时的字体 var article_font = `-apple-system,BlinkMacSystemFont,Helvetica Neue,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC, WenQuanYi Micro Hei,sans-serif`; // 分区标题和描述的映射 var container_title_desciption_mapping = { "近期热门话题": "俗称的论坛十大
关注今天北邮的新鲜事", "近期热点活动": "找点有趣的人,干点有趣的事", "生活时尚": "今天有什么奇思妙想", "信息社会": "工作、读研、考公、创业", "情感的天空": "愿陪你一同走过", "投票": "展示你的态度", "竞猜": "万一猜对了呢", "近期推荐文章": "大家都在看什么", "发文排行榜": "谁发了最多的贴?", "挂站排行榜": "谁看了最久论坛?" // todo: not finished } // ***********************************全局变量************************************* // 原论坛顶栏备份(jquery选择器) var old_header_selector = undefined; // 原论坛左栏备份(jquery选择器) var old_left_bar_selector = undefined; // 解决论坛自带的JQuery和脚本内的JQuery冲突 // https://stackoverflow.com/questions/28264871/require-jquery-to-a-safe-variable-in-tampermonkey-script-and-console this.$ = window.jQuery.noConflict(true); // ***********************************功能实现************************************* // 去除并备份原顶栏 function remove_header() { old_header_selector = $('header#top_head'); old_header_selector.remove(); } // 去除并备份原左栏 function remove_left_bar() { old_left_bar_selector = $('aside#menu'); old_left_bar_selector.remove(); // 移除左栏后,需要右侧区域居中 $('section#main').css({ 'margin-left': '120px', 'margin-right': '120px' }); } // 将要用的控件都放到第一列来,第二列和第三列删除 function keep_only_first_column_of_containers() { $('ul#column2').remove(); $('ul#column3').remove(); $('#columns .column').css('width', '100%'); // @deprectaed 如何将其他列的控件移动到第一列 // 仅选择下一级的选择器是 > li ,或者使用jquery选择器.children() // var left_col = $('ul#column1'); // mid_col.remove().children('li').appendTo(left_col); } // 插入新设计的顶栏 function insert_new_header() { // nh -> new_header, nhl -> new_header_left, nhr -> new_header_right // 因为new_header_right需要float,所以div排列中先右再左 var new_header_html = `
`; // 插入新的header $('body').prepend(new_header_html); $('header').css({ 'height': '80px', 'box-shadow': '0px 1px 1px gray', 'background-color': '#FFFFFF' }); // 设置所有标签横排 $('div#nhl, div#nhr').css({ 'display': 'flex', 'flex-direction': 'row', 'font-size': '1.5em', 'font-family': widget_font }); // 设置所有标签间距 $('div.nhl_div, div.nhr_div').css({ 'padding': '10px' }) // 设置“北邮人论坛” $('div#nhtitle').css({ 'margin-top': '10px' }) $('div#nhtitle > a').css({ 'color': '#1b4e95', 'font-size': '20px' }) // 设置其他标签顶部 $('div.nhl_div:not(#nhlogo, #nhtitle), div.nhr_div').css({ 'margin-top': '20px' }) // 全文搜索的回车监听 $('input#new_fulltext_search').keypress(function (e) { if (e.which == 13) { var query = $('input#new_fulltext_search').val(); query = query.replace(' ', '+'); query = encodeURIComponent(query); window.open(fulltext_search_api + query); return false; } }); // 添加用户的id $('div#nhr').append(old_left_bar_selector.find('div.u-login-id').css({ 'margin-top': '32px' })); } // 将主体区域的背景色设置为论坛蓝 function set_mainframe_background_color() { $('body:not(header)').css({ 'background': '#F2F6F9' }); } // 设置各控件的字体 function set_widgets_font() { $('section#main').css({ 'font-size': '1.4em', 'font-family': widget_font }) } // 将贴图秀和好文收录放在顶部双栏显示 function raise_picshow_and_topposts() { var prompt_if_not_exist = `

  • 此处应为{widget_name}


    点击此处,将贴图秀栏目加入到第一列,再刷新
    小提示:打开脚本后,只有显示第一列的栏目,请将关心的栏目都放到第一列哦

  • `; // 贴图秀 var picshow = $('li#picshow').remove(); // 经反馈,有时不叫picshow,叫board-Picture if (picshow.length == 0) { picshow == $('li#board-Picture').remove(); } // 如果还是没有,提示添加 if (picshow.length == 0) { picshow = $(prompt_if_not_exist.format('贴图秀')); } // 好文收录 var topposts = $('li#topposts').remove(); if (topposts.length == 0) { topposts = $(prompt_if_not_exist.format('好文收录')); } // picshow and topposts 合成一个ul var combined = $('