Skip to content

Commit

Permalink
element-ready 现在默认 stopOnDomReady
Browse files Browse the repository at this point in the history
不再需要额外封装一次了
  • Loading branch information
riophae committed Aug 18, 2019
1 parent 199cb07 commit c54027d
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/content/modules/notification.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h } from 'dom-chef'
import select from 'select-dom'
import elementReady from 'element-ready'
import sleep from 'p-sleep'
import safeElementReady from '@libs/safeElementReady'
import { fadeIn, fadeOut } from '@libs/fade'

const FADE_DURATION = 500
Expand Down Expand Up @@ -39,8 +39,8 @@ async function animate(element) {

export default {
async ready() {
container = await safeElementReady('#container')
header = await safeElementReady('#header')
container = await elementReady('#container')
header = await elementReady('#header')

return container && header
},
Expand Down
4 changes: 2 additions & 2 deletions src/content/modules/statusFormIntersectionObserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import elementReady from 'element-ready'
import wrapper from '@libs/wrapper'
import safeElementReady from '@libs/safeElementReady'
import safelyInvokeFns from '@libs/safelyInvokeFns'
import arrayUniquePush from '@libs/arrayUniquePush'
import arrayRemove from '@libs/arrayRemove'
Expand Down Expand Up @@ -41,7 +41,7 @@ function intersectionObserverCallback([ { intersectionRatio } ]) {

export default wrapper({
async install() {
const update = await safeElementReady('#phupdate')
const update = await elementReady('#phupdate')

if (update) {
createSpy(update)
Expand Down
4 changes: 2 additions & 2 deletions src/content/modules/timelineElementObserver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import select from 'select-dom'
import elementReady from 'element-ready'
import wrapper from '@libs/wrapper'
import safeElementReady from '@libs/safeElementReady'
import safelyInvokeFns from '@libs/safelyInvokeFns'
import arrayUniquePush from '@libs/arrayUniquePush'
import arrayRemove from '@libs/arrayRemove'
Expand Down Expand Up @@ -64,7 +64,7 @@ function getStatuses() {

export default wrapper({
async install() {
stream = await safeElementReady('#stream')
stream = await elementReady('#stream')

if (stream) {
observer = new MutationObserver(streamMutationObserver)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h } from 'dom-chef'
import select from 'select-dom'
import elementReady from 'element-ready'
import wretch from 'wretch'
import safeElementReady from '@libs/safeElementReady'
import { isFriendRequestPage } from '@libs/pageDetect'
import untilElementRemoved from '@libs/untilElementRemoved'
import neg from '@libs/neg'
Expand Down Expand Up @@ -131,7 +131,7 @@ export default context => {
return {
applyWhen: () => isFriendRequestPage(),

waitReady: () => safeElementReady('#footer'),
waitReady: () => elementReady('#footer'),

onLoad() {
createContainer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from 'dom-chef'
import select from 'select-dom'
import elementReady from 'element-ready'
import wretch from 'wretch'
import { isLoggedInUserFriendsListPage, isLoggedInUserFollowersListPage, isFriendsListPage } from '@libs/pageDetect'
import safeElementReady from '@libs/safeElementReady'
import untilElementRemoved from '@libs/untilElementRemoved'
import promiseAny from '@libs/promiseAny'

Expand Down Expand Up @@ -121,7 +121,7 @@ export default context => {
isLoggedInUserFollowersListPage(),
]),

waitReady: () => safeElementReady('#footer'),
waitReady: () => elementReady('#footer'),

onLoad() {
createMasterCheckbox()
Expand Down
4 changes: 2 additions & 2 deletions src/features/batch-remove-private-messages/script(page).js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from 'dom-chef'
import select from 'select-dom'
import elementReady from 'element-ready'
import wretch from 'wretch'
import { isPrivateMessagePage } from '@libs/pageDetect'
import safeElementReady from '@libs/safeElementReady'
import untilElementRemoved from '@libs/untilElementRemoved'

const CLASSNAME_CHECKBOX = 'sf-private-message-checkbox'
Expand Down Expand Up @@ -99,7 +99,7 @@ export default context => {
return {
applyWhen: () => isPrivateMessagePage(),

waitReady: () => safeElementReady('#footer'),
waitReady: () => elementReady('#footer'),

onLoad() {
createMasterCheckbox()
Expand Down
4 changes: 2 additions & 2 deletions src/features/batch-remove-statuses/script(page).js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from 'dom-chef'
import select from 'select-dom'
import elementReady from 'element-ready'
import wretch from 'wretch'
import { isLoggedInUserProfilePage } from '@libs/pageDetect'
import safeElementReady from '@libs/safeElementReady'
import collapseSelection from '@libs/collapseSelection'
import noop from '@libs/noop'

Expand Down Expand Up @@ -258,7 +258,7 @@ export default context => {
return {
applyWhen: () => isLoggedInUserProfilePage(),

waitReady: () => safeElementReady('#footer'),
waitReady: () => elementReady('#footer'),

onLoad() {
createContainer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import elementReady from 'element-ready'
import requireFanfouLib from '@libs/requireFanfouLib'
import keepRetry from '@libs/keepRetry'
import safeElementReady from '@libs/safeElementReady'

export default () => {
let $textarea

return {
async applyWhen() {
const $ = await requireFanfouLib('jQuery')
const textarea = await safeElementReady('#phupdate textarea')
const textarea = await elementReady('#phupdate textarea')

return textarea && ($textarea = $(textarea))
},
Expand Down
6 changes: 3 additions & 3 deletions src/features/go-top-button/script(page).js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import select from 'select-dom'
import elementReady from 'element-ready'
import { h } from 'dom-chef'
import debounce from 'just-debounce-it'
import safeElementReady from '@libs/safeElementReady'
import animatedScrollTop from '@libs/animatedScrollTop'
import any from '@libs/promiseAny'

Expand Down Expand Up @@ -78,8 +78,8 @@ export default context => {

return {
applyWhen: () => any([
safeElementReady('#stream'),
safeElementReady('.inner-content'),
elementReady('#stream'),
elementReady('.inner-content'),
]),

onLoad() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import createActivityDetector from 'activity-detector'
import select from 'select-dom'
import elementReady from 'element-ready'
import isVisible from 'is-visible'
import getLoggedInUserProfilePageUrl from '@libs/getLoggedInUserProfilePageUrl'
import safeElementReady from '@libs/safeElementReady'

export default context => {
const { readOptionValue, requireModules, elementCollection, registerDOMEventListener } = context
Expand Down Expand Up @@ -83,7 +83,7 @@ export default context => {
return {
applyWhen: () => elementCollection.ready('timelineNotification'),

waitReady: () => safeElementReady('#stream'),
waitReady: () => elementReady('#stream'),

onLoad() {
statusFormIntersectionObserver.addListener(intersectionObserverCallback)
Expand Down
4 changes: 2 additions & 2 deletions src/features/remove-brackets/script(content).js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import select from 'select-dom'
import safeElementReady from '@libs/safeElementReady'
import elementReady from 'element-ready'

async function removeBrackets(selector) {
const found = await safeElementReady(selector)
const found = await elementReady(selector)
if (!found) return

for (const element of select.all(selector)) {
Expand Down
4 changes: 2 additions & 2 deletions src/features/remove-personalized-theme/script(content).js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from 'dom-chef'
import elementReady from 'element-ready'
import fanfouDefaultThemeCss from './fanfou-default-theme'
import findUserThemeStyleElement from '@libs/findUserThemeStyleElement'
import keepRetry from '@libs/keepRetry'
import safeElementReady from '@libs/safeElementReady'
import getLoggedInUserId from '@libs/getLoggedInUserId'
import arrayUniquePush from '@libs/arrayUniquePush'
import arrayRemove from '@libs/arrayRemove'
Expand Down Expand Up @@ -30,7 +30,7 @@ export default context => {
}

async function extractUserIdFromMeta() {
const meta = await safeElementReady('meta[name="author"]')
const meta = await elementReady('meta[name="author"]')

if (meta) {
const rawValue = meta.getAttribute('content')
Expand Down
4 changes: 2 additions & 2 deletions src/features/update-timestamps/script(page).js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import select from 'select-dom'
import elementReady from 'element-ready'
import requireFanfouLib from '@libs/requireFanfouLib'
import safeElementReady from '@libs/safeElementReady'
import every from '@libs/promiseEvery'

const INTERVAL_DURATION = 15 * 1000
Expand All @@ -22,7 +22,7 @@ export default () => {
}

return {
applyWhen: () => safeElementReady('#stream'),
applyWhen: () => elementReady('#stream'),

waitReady: () => every([
requireFanfouLib('FF.util.parseDate'),
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ElementCollection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import select from 'select-dom'
import safeElementReady from '@libs/safeElementReady'
import elementReady from 'element-ready'

export default class ElementCollection {
constructor() {
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class ElementCollection {
}

if (!entry.promise) {
entry.promise = safeElementReady(entry.selector)
entry.promise = elementReady(entry.selector)
}

return entry.promise
Expand Down
10 changes: 5 additions & 5 deletions src/libs/pageDetect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import select from 'select-dom'
import simpleMemoize from 'just-once'
import safeElementReady from '@libs/safeElementReady'
import elementReady from 'element-ready'
import getLoggedInUserId from '@libs/getLoggedInUserId'
import getLoggedInUserProfilePageUrl from '@libs/getLoggedInUserProfilePageUrl'
import any from '@libs/promiseAny'
Expand Down Expand Up @@ -36,7 +36,7 @@ export function isLoggedInUserProfilePage() {
export const isLoggedInUserFriendsListPage = simpleMemoize(async () => {
if (!isFriendsListPage()) return false

await safeElementReady('#stream')
await elementReady('#stream')

const urlA = select('.tabs .crumb').href
const urlB = getLoggedInUserProfilePageUrl()
Expand All @@ -48,7 +48,7 @@ export const isLoggedInUserFriendsListPage = simpleMemoize(async () => {
export const isLoggedInUserFollowersListPage = simpleMemoize(async () => {
if (!isFollowersListPage()) return false

await safeElementReady('#stream')
await elementReady('#stream')

const urlA = select('.tabs .crumb').href
const urlB = getLoggedInUserProfilePageUrl()
Expand All @@ -60,7 +60,7 @@ export const isLoggedInUserFollowersListPage = simpleMemoize(async () => {
export const isUserProfilePage = simpleMemoize(() => {
return any([
// 只有用户个人页面中才存在「投诉」对话框
safeElementReady('#overlay-report'),
elementReady('#overlay-report'),
// 但是当前登录用户的个人页面中没有「投诉」对话框,需要额外判断
isLoggedInUserProfilePage(),
])
Expand Down Expand Up @@ -133,7 +133,7 @@ export function isFriendRequestPage() {
// 判断是否为 timeline 页面,例如首页、用户个人页面、随便看看页面等
export const isTimelinePage = simpleMemoize(() => every([
// timeline 的页面都有 #stream 元素
safeElementReady('#stream'),
elementReady('#stream'),
// 管理关注请求页面也有 #stream 元素,而且 DOM 结构和一般 timeline 页面难以区分,排除之
neg(isFriendRequestPage()),
]))
Expand Down
4 changes: 0 additions & 4 deletions src/libs/safeElementReady.js

This file was deleted.

0 comments on commit c54027d

Please sign in to comment.