Skip to content

Commit

Permalink
Update xpath values and add tab keypress event.
Browse files Browse the repository at this point in the history
  • Loading branch information
biplobsd committed Nov 3, 2023
1 parent a2b8c2a commit 7bfc0a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions data/xpath.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"IS_EXPENDEDABLE_EXPENDED_BUTTON": "//*[contains(normalize-space(), 'Subscriptions')]/following-sibling::div[@id='items']/ytd-guide-collapsible-entry-renderer/ytd-guide-entry-renderer",
"THREE_LINES": "//yt-icon-button[@id='guide-button']",
"DRAWER_OPENED": "//div[@id='contentContainer' and @opened]",
"ALREADY_SUBSCRIBE": "//*[contains(normalize-space(), '{{channelID}}')]/..//div[@id='notification-preference-button' and not(@invisible)]//span[text()='Subscribed']",
"SUBSCRIBE_BTN": "//*[contains(normalize-space(), '{{channelID}}')]/..//div[@id='subscribe-button']//span[text()='Subscribe']/ancestor::button",
"ALREADY_SUBSCRIBE": "//span[translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{{channelID}}']/ancestor::div[@id='info-section']//div[@id='notification-preference-button' and not(@invisible)]//span[text()='Subscribed']",
"SUBSCRIBE_BTN": "//span[translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{{channelID}}']/ancestor::div[@id='info-section']//div[@id='subscribe-button']//span[text()='Subscribe']/ancestor::button",
"UNSUB1": "//yt-formatted-string[text()='Unsubscribe']",
"UNSUB2": "//button[@aria-label='Unsubscribe']",
"SEARCH_INPUT": "//input[@id='search']",
"NAVIGATION_PROGRESS": "//yt-page-navigation-progress[@hidden]"
"NAVIGATION_PROGRESS": "//yt-page-navigation-progress[not(@hidden)]"
}
16 changes: 12 additions & 4 deletions src/content/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { XPathModel } from "src/utils/xpaths";
let isRunning: boolean = false;
let stop: boolean = false;
let xpathValues: XPathModel;
let isNotTabRegister = true;

function getAlreadySubscribeXpath(channelID: string) {
return xpathValues.ALREADY_SUBSCRIBE.replace("{{channelID}}", channelID);
Expand All @@ -29,10 +30,12 @@ async function searchChannel(channelID: string) {
xpathValues.SEARCH_INPUT
) as HTMLInputElement;
if (search) {
if (isNotTabRegister) {
search.dispatchEvent(new KeyboardEvent("keypress", { key: "Tab" }));
await delay(100);
}
search.value = channelID;
search.dispatchEvent(
new KeyboardEvent("keydown", { key: "Enter", keyCode: 13 })
);
search.dispatchEvent(new KeyboardEvent("keydown", { keyCode: 13 }));
return true;
}
return false;
Expand All @@ -47,10 +50,14 @@ async function switchChannel(channelID: string) {
}

async function waitingForProgressEnd() {
for (let index = 0; index < 20; index++) {
await delay(100);
for (let index = 0; index < 50; index++) {
if (!isXPathExpressionExists(xpathValues.NAVIGATION_PROGRESS)) {
return true;
}
if (isNotTabRegister) {
isNotTabRegister = false;
}
await delay(500);
}
return false;
Expand Down Expand Up @@ -381,6 +388,7 @@ async function unSubSubNow(channelID: string) {
const unSub2 = getXpathFromElement(xpathValues.UNSUB2);
if (unSub2) {
unSub2.click();
await delay(50);
if (isXPathExpressionExists(getSubscribeButton(channelID))) {
await runtime.send({
type: "statusOption",
Expand Down

0 comments on commit 7bfc0a8

Please sign in to comment.