// ==UserScript== // @name MDSteamCN // @namespace http://tampermonkey.net/ // @version 0.15 // @description md化SteamCN // @author marioplus // @match https://steamcn.com/* // @require https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js // @run-at document-body // @downloadURL none // ==/UserScript== (function () { // 执行一些公共操作 // 随机配色 function generateRandomColors(type, index) { // 主色调、副色调、强调色 const colors = [ // 日间主题 [ // 浅色 ['red', 'white'], ['pink', 'white'], ['purple', 'white'], ['deep-purple', 'white'], ['indigo', 'white'], ['teal', 'white'], // 深色 ['blue', 'black'], ['light-blue', 'black'], ['cyan', 'black'], ['green', 'black'], ['light-green', 'black'], ['lime', 'black'], ['yellow', 'black'], ['amber', 'black'], ['orange', 'black'], ['deep-orange', 'black'], ], // 夜间主题 [ // 浅色 ['red', 'white'], ['pink', 'white'], ['purple', 'white'], ['deep-purple', 'white'], ['indigo', 'white'], ['teal', 'white'], // 深色 ['blue', 'black'], ['light-blue', 'black'], ['cyan', 'black'], ['green', 'black'], ['light-green', 'black'], ['lime', 'black'], ['yellow', 'black'], ['amber', 'black'], ['orange', 'black'], ['deep-orange', 'black'], ] ] index = index === undefined ? Math.floor(Math.random() * colors.length) : index type = 0 return { theme: colors[type][index][0], nav: colors[type][index][1], } } // 加载css/js资源 function loadResource() { $('head') // mdui .append('') .append('') .append(initCss()) // .append(initHomeCss()) } // 初始需要的css function initCss() { return ` ` } // 初始主题 function initTheme(color) { $('body').addClass(`mdui-theme-primary-${color.theme} mdui-theme-accent-${color.nav}`) } // appbar function generateAppbar(navColor) { // 解析数据格式 const MENU_TYPE_CONTENT = 1, MENU_TYPE_DIVIDER = 0 let data = { menu: [ { text: '平台', icon: 'near_me', color: 'blue', item: [ {href: 'f161-1', text: '热点'}, {href: 'f319-1', text: '福利'}, {href: 'f234-1', text: '购物'}, {href: 'f271-1', text: '慈善包'}, {href: 'f257-1', text: '汉化'}, {href: 'f189-1', text: '资源'}, {href: 'f127-1', text: '研讨'}, {href: 'f235-1', text: '成就'}, {href: 'f129-1', text: '互鉴'}, {href: 'f254-1', text: '分享互赠'} ] }, { text: '互助', icon: 'enhanced_encryption', color: 'deep-orange', item: [ {href: 'f301-1', text: '技术'}, {href: 'f302-1', text: '购物'}, {href: 'f304-1', text: '社区'}, {href: 'f318-1', text: '资源'}, {href: 'f303-1', text: '游戏'}, {href: 'f322-1', text: '软硬'}, {href: 'f311-1', text: '魔法'}, ] }, { text: '友商', icon: 'child_friendly', color: 'green', item: [ {href: 'f232-1', text: 'Origin'}, {href: 'f274-1', text: 'uPlay'}, {href: 'f276-1', text: 'GOG'}, {href: 'f316-1', text: '杉果'}, {href: 'f326-1', text: 'Windows'}, {href: 'f332-1', text: '方块'}, {href: 'f325-1', text: 'WeGame'}, {href: 'f275-1', text: '主机'}, {href: 'f328-1', text: '移动'}, {href: 'f277-1', text: '其他'}, ] }, { text: '休闲', icon: 'exposure_plus_1', color: 'brown', item: [ {href: 'f148-1', text: '水区'}, {href: 'f259-1', text: '摄影'}, {href: 'f273-1', text: '美食'}, {href: 'f200-1', text: '软硬'}, ] }, { text: '服务', icon: 'local_mall', color: 'purple', item: [ {href: 'f140-1', text: '公告'}, {href: 'f197-1', text: '反馈'}, {href: 'f238-1', text: '活动'}, ] }, { text: '社区', icon: 'flag', color: 'amber', item: [ {href: 'f251-1', text: '综合交流 交换观点/资源'}, {href: 'f305-1', text: 'DOTA'}, {href: 'f299-1', text: 'CSGO'}, {href: 'f291-1', text: '生存类'}, {href: 'f312-1', text: 'GTA'}, {href: 'f244-1', text: '威乐'}, {href: 'f246-1', text: '艺电'}, {href: 'f245-1', text: '育碧'}, {href: 'f248-1', text: '动视暴雪'}, ] }, { text: '其乐', icon: 'hot_tub', color: 'red', item: [ {href: 'https://www.keylol.com', text: '其乐'}, ] }, { text: '赠楼', icon: 'view_carousel', color: 'pink', item: [ {href: 'f148-1', text: '互赠平台'}, ] }, { text: '交易', icon: 'local_atm', color: 'cyan', item: [ {href: 'steamcn_gift-7l.html', text: '交易中心 便捷游戏市集'}, ] }, { text: '休闲', icon: 'fingerprint', color: 'green', item: [ {href: 'steamcn_gift-7l.html', text: '水区'}, ] }, ], nav: [ {text: 'home', href: '/home'} ], userInfo: { isLogon: false, messageTagInfo: { select: 'a.btn.btn-user-action:first > span', href: 'home.php?mod=space&do=pm', icon: 'email', }, remindTagInfo: { select: 'a.btn.btn-user-action:last > span', href: 'home.php?mod=space&do=notice&view=system', icon: 'notifications', }, avatar: { img: '', menu: [ { type: MENU_TYPE_CONTENT, href: 'javascript:;', onclick: '', text: '' }, { type: MENU_TYPE_DIVIDER } ] } } } parseData() replacerAppbar() // 解析数据 function parseData() { parseNav() parseUserInfo() // 解析面包屑导航栏 function parseNav() { data.nav = [] $('.subforum_left_title_left_up > div > a').each((i, e) => { data.nav.push({ href: e.getAttribute('href'), text: e.innerText }) }) } function parseUserInfo() { const $dropdown = $('.list-inline > .dropdown') if ($dropdown.length <= 0) { data.userInfo.isLogon = false } else { data.userInfo.isLogon = true parseAvatarImg() parseMenu() } // 解析头像 function parseAvatarImg() { data.userInfo.avatar.img = $('img.avatar.img-circle').attr('src') } // 解析菜单 function parseMenu() { data.userInfo.avatar.menu = [] // 单独添加个人中心 data.userInfo.avatar.menu.push({ type: MENU_TYPE_CONTENT, href: $dropdown.find('a').attr('href'), onclick: null, text: '个人中心', }) $dropdown.find('li').each((i, e) => { let item = {} if (e.getAttribute('class') !== 'divider') { let find = e.getElementsByTagName('a')[0] item = { type: MENU_TYPE_CONTENT, href: find.getAttribute('href'), onclick: find.getAttribute('onclick'), text: find.innerText } } else { item = {type: MENU_TYPE_DIVIDER} } data.userInfo.avatar.menu.push(item) }) } } } // 替换 appbar function replacerAppbar() { // 面包屑导航 function generateNav() { if (data.nav.length > 0) { let tmp = '' data.nav.forEach((e, i) => { tmp += `${e.text}` // html += `${e.text}` if (i < data.nav.length - 1) { tmp += `>` } }) return `
${tmp}
` } return '' } // 消息、提醒、头像 function generateMsgAndRemindAndAvatar() { if (!data.userInfo.isLogon) { return '' } return generateMsgAndRemind() + generateAvatarMenu() function generateMsgAndRemind() { function gen(tagInfo) { const $tag = $(tagInfo.select) return `${tagInfo.icon} ${$tag.text()}` } return gen(data.userInfo.messageTagInfo) + gen(data.userInfo.remindTagInfo) } // 头像菜单 function generateAvatarMenu() { let html = ` ' return html } } //TODO: 待开发 登录、注册 function generateLoginAndRegister() { console.log(2) return '' } // Appbar 菜单选项 function generateAppbarMenu() { let html = '' data.menu.forEach((e) => { html += `
${e.icon}
${e.text}
keyboard_arrow_down
` e.item.forEach((f) => { html += `${f.text}` }) html += '
' }) return html } // 生成 $('body').prepend(`
menu SteamCN ${generateNav()}
search ${data.userInfo.isLogon ? generateMsgAndRemindAndAvatar() : generateLoginAndRegister()}
${generateAppbarMenu()}
`) $('#nav-menu').remove() $('.tb-container').remove() } } // 帖子标题 浏览数据 function generatePostTitleAndAttr() { let data = { // 标题 title: '', // 访问数据 attr: { reply: { text: '回复', amount: '', onclick: '' }, view: { text: '查看', amount: '' }, favorite: { text: '收藏', amount: '', onclick: '' } } } parseData() remove() generate() function parseData() { data.title = $('a#thread_subject').attr('title') const $postData = $('div.subforum_right_title > div div:odd') const $postFavorite = $('#k_favorite') const $postReply = $('#post_reply') data.attr = { reply: { text: '回复', amount: $postData[0].innerText, onclick: $postReply.attr('onclick') }, view: { text: '查看', amount: $postData[1].innerText }, favorite: { text: '收藏', amount: $postData[2].innerText, onclick: `showWindow('k_favorite', '${$postFavorite.attr('href')}', 'get', 0);` } } } function remove() { $('#pgt, div.subforum').remove() } function generate() { $('body').prepend(`

${data.title}

`) } } // 帖子内容 md化 function mdPost() { $('body').append(`
`) mdContent() generateBtnGroup() mdReply() mdPostSelf() mdPostOthers() // 帖子 function mdContent() { // 鼠标悬浮加深阴影 阴影 $('#postlist').addClass('mdui-hoverable mdui-shadow-5') // 回复间隙 改为主题色 $('.ad').addClass('mdui-color-theme') // 帖子-回复按钮 $('.pob.cl a').addClass('mdui-btn mdui-ripple mdui-btn-dense') } // 回复页数 按钮组 function generateBtnGroup() { //
//
// chevron_left // 1 // 2 // 3 // 4 // 5 // 6 // 7 // 8 // 9 // 10 // ...32 // chevron_right //
//
// 查找特殊节点 function findPage(cName) { const tmpNode = $(`.pg .${cName}`) if (tmpNode === undefined) { return undefined } return { text: tmpNode.text(), href: tmpNode.attr('href') } } function addTextBtn(data, isActive) { return `${data.text}` } function addIconBtn(data, icon) { return `${icon}` } let pervPage = findPage('prev') let firstPage = findPage('first') let lastPage = findPage('last') let nextPage = findPage('nxt') let pageGroupHtml = `
` if (pervPage.href) { pageGroupHtml += addIconBtn(pervPage, 'chevron_left') } if (firstPage.href) { pageGroupHtml += addTextBtn(firstPage, false) } $('.pg > a:not(.first,.prev,.nxt,.last),.pg > strong').each((i, e) => { const date = { href: e.href === undefined ? 'javascript:;' : e.href, text: e.innerText } pageGroupHtml += addTextBtn(date, e.href === undefined) }) if (lastPage.href) { pageGroupHtml += addTextBtn(lastPage, false) } if (nextPage.href) { pageGroupHtml += addIconBtn(nextPage, 'chevron_right') } pageGroupHtml += `
` $('#postlist').append(pageGroupHtml) // 隐藏默认 $('.pgbtn,.pgs.mtm.mbm.cl').remove() } // 底部回复区域 function mdReply() { // 回复按钮 $('#f_pst').appendTo('#postlist') .prepend('
') $('#fastpostsubmit').replaceWith('') // $('p.ptm.pnpost').addClass('mdui-valign') $('p.ptm.pnpost a.y').appendTo('p.ptm.pnpost') // 回帖跳转最后一页 $('label[for=fastpostrefresh]').addClass('mdui-checkbox') .append('') } // 帖子正文 function mdPostSelf() { function genBtn(e, text) { return `${text}` } // 收藏、评分按钮 let $k_favorite = $('a#k_favorite') let $ak_rate = $('a#ak_rate') $k_favorite.replaceWith(genBtn($k_favorite, '收藏')) $ak_rate.replaceWith(genBtn($ak_rate, '评分')) } // 其回复 function mdPostOthers() { } } function mdOther() { generateScrollTopBtn() // 返回顶部按钮 function generateScrollTopBtn() { $('body').append('') let scrollTopHide = true $(window).scroll(() => { if ($(window).scrollTop() > 100) { // 显示 if (scrollTopHide) { scrollTopHide = !scrollTopHide $('#my_ScrollTopBtn').removeClass('mdui-fab-hide') } } else { // 隐藏 if (!scrollTopHide) { scrollTopHide = !scrollTopHide $('#my_ScrollTopBtn').addClass('mdui-fab-hide') } } }) $(window).trigger('scroll') $('#my_ScrollTopBtn').on('click', () => { $('html,body').finish().animate({'scrollTop': '0px'}, 500) }) } } const THEME_TYPE_DATLE = 0, THEME_TYPE_NIGHT = 1 // 初始化操作 function init() { loadResource() let randomColors = generateRandomColors(THEME_TYPE_DATLE) initTheme(randomColors) generateAppbar(randomColors.nav) } // 判断4类不同的页面 const locationHref = window.location if (/^https:\/\/steamcn.com\/(forum.php(\?gid=\d+)?)?$/.test(locationHref)) { /* * 首页 * https://steamcn.com/ * https://steamcn.com/forum.php/ */ console.log('home') } else if (/^https:\/\/steamcn.com\/(f\d+)|(forum.php\?mod=forumdisplay)/.test(locationHref)) { /* * 目录 * https://steamcn.com/f274-1 * https://steamcn.com/forum.php?mod=forumdisplay&fid=274&filter=typeid&typeid=348 */ console.log('forum display') } else if (/^https:\/\/steamcn.com\/(t\d+)|(forum.php\?mod=viewthread)/.test(locationHref)) { /* * 帖子 * https://steamcn.com/t368540-1-1 * https://steamcn.com/forum.php?mod=viewthread&tid=368540&page=1#pid6102860 */ console.log('post') init() generatePostTitleAndAttr() mdPost() mdOther() } else if (/^https:\/\/steamcn.com\/home.php/.test(locationHref)) { /* * 个人页面 * https://steamcn.com/t368540-1-1 * https://steamcn.com/forum.php?mod=viewthread&tid=368540&page=1#pid6102860 */ console.log('profile') } else { console.log('unknown') } })()