// ==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 `