// ==UserScript== // @name bilibili直播自定义皮肤背景 // @namespace http://tampermonkey.net/ // @version 2.1.5 // @description 自定义bilibili直播的皮肤和背景,仅自己可见! // @author HCLonely // @include /^https?:\/\/live.bilibili.com\/(blanc\/)?[\d]+/ // @run-at document-end // @connect api.live.bilibili.com // @connect * // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @require https://cdn.jsdelivr.net/npm/jquery@3.4.0/dist/jquery.min.js // @homepage https://blog.hclonely.com/posts/578f9be7/ // @supportURL https://blog.hclonely.com/posts/578f9be7/ // @downloadURL https://update.greasyfork.icu/scripts/387120/bilibili%E7%9B%B4%E6%92%AD%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%AE%E8%82%A4%E8%83%8C%E6%99%AF.user.js // @updateURL https://update.greasyfork.icu/scripts/387120/bilibili%E7%9B%B4%E6%92%AD%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%AE%E8%82%A4%E8%83%8C%E6%99%AF.meta.js // ==/UserScript== (function () { 'use strict'; //$('#live-player-ctnr>div').html('test') const skinConfig = Object.prototype.toString.call(GM_getValue('skinConfig')) === "[object Object]" ? GM_getValue('skinConfig') : {0: { id: 0, skin_name: '默认' }} let selectedSkin = GM_getValue('selectedSkin') || 0 let customedBgimg = GM_getValue('customedBgimg') || 0 let selectedSkinConfig = {} if (selectedSkin !== 0 && skinConfig[selectedSkin]) { selectedSkinConfig = preProcessing(skinConfig[selectedSkin].skin_config) generateStyle() } if (customedBgimg) { changeBackgroundImage(customedBgimg) } const init = setInterval(() => { if ($('.icon-left-part').length > 0) { clearInterval(init) // const iconLocation = ($('.control-panel-icon-row .icon-item').length + 1) * 23 $('#skin-css').remove() $('.icon-left-part').after(`自定义皮肤`) $('#skin-setting-icon').click(() => { if ($('#skin-setting-div').length > 0) { $('#skin-setting-div').hide('fast', () => { $('#skin-setting-div').remove() }) } else { let html = '' for (const config of Object.values(skinConfig)) { if(config.id < 0){ html = `
  • ` + html } else { html += `
  • ` } } $('#control-panel-ctnr-box').append(` `) $('#skin-setting-div').show('normal') const container = $('#skin-container') const inner = $('#skin-selected') console.log(container, inner) container.scrollTop(inner.offset().top - container.offset().top + container.scrollTop()) $("input.background-custom").bind('input porpertychange', function () { if ($(this).val().length > 0) { $('button.change-bgimg').removeAttr('disabled') } else { $('button.change-bgimg').attr('disabled', 'disabled') } }) $('button.change-bgimg').click(function () { customedBgimg = $("input.background-custom").val() if (customedBgimg === '0'){ customedBgimg = 0 }else{ changeBackgroundImage(customedBgimg) } GM_setValue('customedBgimg', customedBgimg) }) $('#skin-setting-div .item').click(function (e) { if (e.target === $(this).find('input')[0]) { $('#skin-setting-div .item>span.svg-icon').removeClass('checkbox-selected').addClass('checkbox-default') $(this).find('span.svg-icon').removeClass('checkbox-default').addClass('checkbox-selected') selectedSkin = parseInt($(this).attr('data-id')) if (selectedSkin !== 0) { selectedSkinConfig = preProcessing(skinConfig[selectedSkin].skin_config) generateStyle() } GM_setValue('selectedSkin', selectedSkin) } }) $('button.custom-skin').click(function () { $('#sections-vm').remove() let html = '' for(const name of Object.keys(selectedSkinConfig)){ if (name === 'highlightContentHover') continue html += `${name}:预览
    ` } html += `自定义主题名称:
    ` $('#live-player-ctnr>div').css('text-align', 'center').html(`
    ${html}
    `) $("input.skin-config-custom").focus(function () { toggleHighlightElement($(this).attr('data-name'), true) }) $("input.skin-config-custom").blur(function () { toggleHighlightElement($(this).attr('data-name'), false) }) $("input.skin-config-custom").bind('input porpertychange', function () { if ($(this).val().length > 0) { $('button.change-skin').removeAttr('disabled') } else { $('button.change-skin').attr('disabled', 'disabled') } }) $("input.skin-name-custom").bind('input porpertychange', function () { if ($(this).val().length > 0) { $('button.save-skin').removeAttr('disabled') } else { $('button.save-skin').attr('disabled', 'disabled') } }) $('button.change-skin').click(function(){ selectedSkinConfig[$(this).attr('data-name')] = $(this).prev().val() generateStyle() }) $('button.save-skin').click(function () { skinConfig[-1] = { "id": -1, "skin_name": $('input.skin-name-custom').val(), "skin_config": { "headInfoBgPic": $('input[data-name="headInfoBgPic"]').val(), "giftControlBgPic": $('input[data-name="giftControlBgPic"]').val(), "rankListBgPic": $('input[data-name="rankListBgPic"]').val(), "mainText": $('input[data-name="mainText"]').val(), "normalText": $('input[data-name="normalText"]').val(), "highlightContent": $('input[data-name="highlightContent"]').val(), "border": $('input[data-name="border"]').val() } } GM_setValue('skinConfig', skinConfig) $('#skin-setting-div .list').prepend(`
  • `) $('#live-player-ctnr>div>div').append('
    保存成功!
    ') setTimeout(()=>{ $('#saved').remove() }, 3000) }) }) } }) $(document).on('click', function (e) { const skinSettingDiv = $('#skin-setting-div') const skinSettingIcon = $('#skin-setting-icon') if (!skinSettingDiv.is(e.target) && skinSettingDiv.has(e.target).length === 0 && !skinSettingIcon.is(e.target) && skinSettingIcon.has(e.target).length === 0) { skinSettingDiv.hide('fast', () => { skinSettingDiv.remove() }) } }) updateSkinConfig(Math.max(...Object.keys(skinConfig)) + 1) } }) function updateSkinConfig(id) { GM_xmlhttpRequest({ url: `https://api.live.bilibili.com/room/v1/Skin/info?skin_platform=web&skin_version=1&id=${id}`, methon: 'get', responseType: 'json', onload: data => { if (data.response.code === 0 && !Array.isArray(data.response.data)) { const skinData = data.response.data skinData.skin_config = JSON.parse(skinData.skin_config) skinConfig[skinData.id] = skinData GM_setValue('skinConfig', skinConfig) $('#skin-setting-div .list').append(`
  • `) updateSkinConfig(++id) } } }) } function changeBackgroundImage(url) { GM_xmlhttpRequest({ url: url, methon: 'get', responseType: 'blob', onload: data => { if(data.status === 200){ $('[role="img.webp"]').css('background-image', 'url(' + window.URL.createObjectURL(data.response) + ')') } else { $('[role="img.webp"]').css('background-image', 'url(' + url + ')') } }, onerror: () => { $('[role="img.webp"]').css('background-image', 'url(' + url + ')') } }) } function preProcessing(skinConfig) { const mainText = skinConfig.mainText.replace(/#([\d\w]{2})(.+)/, function (match, p1, p2) { if (/^#/.test(match)){ return match.length === 9 ? ('#' + p2 + p1) : match } else { return match } }) const normalText = skinConfig.normalText.replace(/#([\d\w]{2})(.+)/, function (match, p1, p2) { if (/^#/.test(match)) { return match.length === 9 ? ('#' + p2 + p1) : match } else { return match } }) const highlightContent = skinConfig.highlightContent.replace(/#([\d\w]{2})(.+)/, function (match, p1, p2) { if (/^#/.test(match)) { return match.length === 9 ? ('#' + p2 + p1) : match } else { return match } }) const highlightContentHover = skinConfig.highlightContent.replace(/#([\d\w]{2})(.+)/, function (match, p1, p2) { if (/^#/.test(match)) { return match.length === 9 ? ('#' + p2 + 'cc') : match } else { return match } }) const border = skinConfig.border.replace(/#([\d\w]{2})(.+)/, function (match, p1, p2) { if (/^#/.test(match)) { return match.length === 9 ? ('#' + p2 + p1) : match } else { return match } }) return { mainText: mainText, normalText: normalText, highlightContent: highlightContent, highlightContentHover: highlightContentHover, border: border, headInfoBgPic: skinConfig.headInfoBgPic, giftControlBgPic: skinConfig.giftControlBgPic, rankListBgPic: skinConfig.rankListBgPic } } function toggleHighlightElement(name, show = true) { switch (name) { case 'mainText': $('.live-skin-coloration-area .live-skin-main-text,.live-skin-coloration-area .week-icon').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'normalText': $('.live-skin-coloration-area .live-skin-normal-text,.live-skin-coloration-area .live-skin-normal-a-text').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'highlightContent': $('.live-skin-coloration-area .live-skin-highlight-text,.live-skin-coloration-area .live-skin-highlight-bg,.live-skin-coloration-area .live-skin-highlight-border,.live-skin-coloration-area .live-skin-highlight-button-bg.bl-button--primary:not(:disabled)').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'border': $('.live-skin-coloration-area .live-skin-separate-border,.live-skin-coloration-area .live-skin-separate-area').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'headInfoBgPic': $('#head-info-vm').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'giftControlBgPic': $('#gift-control-vm').attr('style', show ? 'border: 2px solid red !important;' : '') break case 'rankListBgPic': $('#rank-list-vm,#rank-list-ctnr-box,#chat-control-panel-vm').attr('style', show ? 'border: 2px solid red !important;' : '') break default: break } } function generateStyle() { const { mainText, normalText, highlightContent, highlightContentHover, border, headInfoBgPic, giftControlBgPic, rankListBgPic } = selectedSkinConfig const skinCss = ` .live-skin-coloration-area .live-skin-main-text { color: ${mainText} !important; fill: ${mainText} !important; } .live-skin-coloration-area .live-skin-main-a-text:link,.live-skin-coloration-area .live-skin-main-a-text:visited { color: ${mainText} !important; } .live-skin-coloration-area .week-icon { color: ${mainText} !important; border-color: ${mainText} !important; } .live-skin-coloration-area .live-skin-main-a-text:hover,.live-skin-coloration-area .live-skin-main-a-text:active { color: ${mainText} !important; } .live-skin-coloration-area .live-skin-normal-text { color: ${normalText} !important; } .live-skin-coloration-area .live-skin-normal-a-text { color: ${normalText} !important; } .live-skin-coloration-area .live-skin-normal-a-text:link,.live-skin-coloration-area .live-skin-normal-a-text:visited { color: ${normalText} !important; } .live-skin-coloration-area .live-skin-normal-a-text:hover,.live-skin-coloration-area .live-skin-normal-a-text:active { color: ${highlightContent} !important; } .live-skin-coloration-area .live-skin-highlight-text { color: ${highlightContent} !important; } .live-skin-coloration-area .live-skin-highlight-bg { background-color: ${highlightContent} !important; } .live-skin-coloration-area .live-skin-highlight-border { border-color: ${highlightContent} !important; } .live-skin-coloration-area .live-skin-highlight-button-bg.bl-button--primary:not(:disabled) { background-color: ${highlightContent}; } .live-skin-coloration-area .live-skin-highlight-button-bg.bl-button--primary:hover:not(:disabled) { background-color: ${highlightContentHover}; } .live-skin-coloration-area .live-skin-highlight-button-bg.bl-button--primary:active:not(:disabled) { background-color: ${highlightContentHover}; } .live-skin-coloration-area .live-skin-separate-border { border-color: ${border} !important; } .live-skin-coloration-area .live-skin-separate-area { background-color: ${border} !important; } .live-skin-coloration-area .live-skin-separate-area-hover:hover { background-color: ${border} !important; } .live-skin-coloration-area .live-skin-button-text:not(:disabled) { color: rgb(201, 204, 208) !important; fill: rgb(201, 204, 208) !important; } #head-info-vm { background-image: url("${headInfoBgPic}"); } #gift-control-vm { background-image: url("${giftControlBgPic}"); } #rank-list-vm,#rank-list-ctnr-box { background-image: url("${rankListBgPic}"); } #chat-control-panel-vm { background-image: url("${rankListBgPic}"); } .supportWebp #head-info-vm { background-image: url("${headInfoBgPic}@90q.webp"); } .supportWebp #gift-control-vm { background-image: url("${giftControlBgPic}@90q.webp"); } .supportWebp #rank-list-vm,.supportWebp #rank-list-ctnr-box { background-image: url("${rankListBgPic}@90q.webp"); } .supportWebp #chat-control-panel-vm { background-image: url("${rankListBgPic}@90q.webp"); } #head-info-vm,#gift-control-vm { border: none !important; padding: 1px; } #aside-area-vm { border: none !important; } #rank-list-vm,#rank-list-ctnr-box { background-repeat: no-repeat; background-size: 100% auto; } #chat-control-panel-vm { background-repeat: no-repeat; background-size: 100% auto; background-position: bottom left; } ` $('#custom-skin').remove() $('head').append(``) } const style = ` .dialog-ctnr.skin-custom { bottom: 100%; padding: 16px; position: absolute; z-index: 699; } .arrow.skin-custom { top: 100%; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 8px solid #fff; } .title.skin-custom { font-weight: 400; font-size: 18px; color: #23ade5; } .link-input.skin-custom { padding: 2px 8px; line-height: 25px; border: 1px solid rgb(201, 204, 208); border-radius: 4px; background-color: #fff; outline: 0; } .link-input.skin-custom:focus { border-color: #23ade5; } .bl-button--primary.skin-custom:disabled, .bl-button--primary.skin-custom:disabled:hover { background-color: #e9eaec; color: #b4b4b4; } .bl-button.skin-custom:disabled { cursor: not-allowed; } button.keyword-submit-btn.skin-custom { min-width: 64px; margin-left: 4px; } .bl-button--small.skin-custom { min-width: 80px; height: 24px; font-size: 12px; } .bl-button--primary.skin-custom { background-color: #23ade5; color: #fff; border-radius: 4px; } .bl-button.skin-custom { position: relative; box-sizing: border-box; line-height: 1; margin: 0; padding: 6px 12px; border: 0; background-color: transparent cursor: pointer; outline: 0; overflow: hidden; } .bl-button--primary.skin-custom:hover { background-color: #39b5e7; } .block-effect-ctnr.skin-custom { margin-top: -4px; } .block-effect-ctnr li.skin-custom, .block-effect-ctnr ul.skin-custom { list-style: none; } .block-effect-ctnr div.skin-custom, .block-effect-ctnr li.skin-custom, .block-effect-ctnr p.skin-custom, .block-effect-ctnr ul.skin-custom { margin: 0; padding: 0; } .block-effect-ctnr .item.skin-custom { color: #666; padding: 6px; } .block-effect-ctnr .item .cb-icon.skin-custom { font-size: 16px; } .block-effect-ctnr .item .cb-icon.skin-custom, .block-effect-ctnr .item input.skin-custom { width: 16px; height: 16px; left: 0; } .block-effect-ctnr .item .cb-icon.skin-custom, .block-effect-ctnr .item input.skin-custom { width: 16px; height: 16px; left: 0; } .block-effect-ctnr .item input.skin-custom { opacity: 0; } .block-effect-ctnr .item label.skin-custom { margin: 0 0 0 2px; } #skin-setting-icon { display: inline-block; width: 24px; height: 24px; margin-left: 4px; margin-top: 4px; fill: rgb(201, 204, 208) !important; } ` GM_addStyle(style) })();