chore: additional stylistic fixes
This commit is contained in:
parent
f41edcb756
commit
e9c16cad10
1 changed files with 37 additions and 36 deletions
|
@ -5,63 +5,64 @@
|
|||
* @param {Event} event
|
||||
*/
|
||||
function onClickFollow(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
const username = window.location.pathname.split(`/`).slice(-1)[0];
|
||||
// activate AutoRemoteFollow
|
||||
window.open(`/users/${username}/remote_follow`, `_blank`);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
const username = window.location.pathname.split(`/`).slice(-1)[0];
|
||||
// activate AutoRemoteFollow
|
||||
window.open(`/users/${username}/remote_follow`, `_blank`);
|
||||
}
|
||||
|
||||
/**
|
||||
* wait for element to appear
|
||||
* @param {string} selector
|
||||
* @param {number} timeout
|
||||
* @see {@link https://github.com/storybookjs/test-runner/blob/6d41927154e8dd1e4c9e7493122e24e2739a7a0f/src/setup-page.ts#L134} from which this was adapted
|
||||
* @see {@link https://github.com/storybookjs/test-runner/blob/6d41927154e8dd1e4c9e7493122e24e2739a7a0f/src/setup-page.ts#L134}
|
||||
* from which this was adapted
|
||||
*/
|
||||
function waitForElement(selector, timeout) {
|
||||
return new Promise((resolve, reject) => {
|
||||
function getElement() {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
function getElement() {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
||||
const element = getElement();
|
||||
if(element){
|
||||
return resolve(element);
|
||||
}
|
||||
const element = getElement();
|
||||
if(element){
|
||||
return resolve(element);
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
const element = getElement();
|
||||
if(element){
|
||||
resolve(element);
|
||||
observer.disconnect();
|
||||
}
|
||||
})
|
||||
const observer = new MutationObserver(() => {
|
||||
const element = getElement();
|
||||
if(element){
|
||||
resolve(element);
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
|
||||
window.setTimeout(() => {
|
||||
reject();
|
||||
}, timeout);
|
||||
})
|
||||
window.setTimeout(() => {
|
||||
reject();
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject replacement onClick handler for Follow button
|
||||
*/
|
||||
async function injectFollowButton() {
|
||||
try {
|
||||
const followButton = await waitForElement(`.account__header__tabs__buttons button.button`, 20000);
|
||||
followButton.addEventListener(`click`, onClickFollow);
|
||||
} catch {
|
||||
// Follow button failed to appear
|
||||
}
|
||||
try {
|
||||
const followButton = await waitForElement(`.account__header__tabs__buttons button.button`, 20000);
|
||||
followButton.addEventListener(`click`, onClickFollow);
|
||||
} catch {
|
||||
// Follow button failed to appear
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await injectFollowButton();
|
||||
await injectFollowButton();
|
||||
}
|
||||
|
||||
init();
|
Loading…
Add table
Add a link
Reference in a new issue