Skip to content

Commit

Permalink
修正有时不能去除 logo 的 beta 字样的问题 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
riophae authored and LitoMore committed Apr 18, 2019
1 parent aacc410 commit 03bda48
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/features/remove-logo-beta/script(content).js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import keepRetry from '@libs/keepRetry'

const CLASSNAME_FEATURE = 'sf-remove-logo-beta'
const RE_BETA_LOGO = /url\("?https?:\/\/static\d?\.fanfou\.com\/img\/fanfou_beta\.(png|svg)"?\)/

Expand All @@ -8,13 +10,23 @@ export default context => {
header: '.global-header-content',
})

function getLogoCssBackgroundImage() {
const { header } = elementCollection.getAll()
const { backgroundImage } = getComputedStyle(header)

return backgroundImage
}

return {
applyWhen: () => elementCollection.ready('header'),

waitReady: () => keepRetry({
checker: () => getLogoCssBackgroundImage() !== 'none',
delay: 0, // 减少等待以尽早完成替换,避免出现闪烁
}),

onLoad() {
const { header } = elementCollection.getAll()
const originalCssBgImg = getComputedStyle(header).backgroundImage
const isBetaLogo = RE_BETA_LOGO.test(originalCssBgImg)
const isBetaLogo = RE_BETA_LOGO.test(getLogoCssBackgroundImage())

// 若遇节日 logo,则不予替换
if (isBetaLogo) document.body.classList.add(CLASSNAME_FEATURE)
Expand Down

0 comments on commit 03bda48

Please sign in to comment.