Skip to content

Commit

Permalink
Closes #957
Browse files Browse the repository at this point in the history
  • Loading branch information
ParticleCore committed Mar 8, 2024
1 parent a394ba5 commit 43d756d
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/chrome/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@
<div class="settingDescription">Allows the creator merch to be shown below the video details</div>
</div>
</div>
<div class="setting" data-id="videoCount">
<label class="switch">
<input data-setting="videoCount" type="checkbox">
<span class="slider"></span>
</label>
<div class="settingDescription">
<div class="settingDescription highlight">Linked video count</div>
<div class="settingDescription">Creates a link that shows the number of videos uploaded by the channel next to the subscriber count</div>
</div>
</div>
</div>
</div>
<div class="settingGroup">
Expand Down
103 changes: 103 additions & 0 deletions src/chrome/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,109 @@ function mainScript(extensionId, SettingData, defaultSettings) {

})();

const FeatureVideoCount = (() => {

const onEvent = () => {

const subCount = document.getElementById("owner-sub-count");

if (!subCount) {
return;
}

const channelId = document.getElementById("movie_player")?.["getPlayerResponse"]()?.["videoDetails"]?.["channelId"] || "";

let url = null;

if (channelId.startsWith("UC")) {
url = `/channel/${channelId}`;
} else if (channelId.startsWith("/@")) {
url = channelId;
} else {
return;
}

if (subCount.parentElement.nodeName !== "A") {

const link = document.createElement("a");

link.href = `${url}/videos`;
link.className = "yt-simple-endpoint";

subCount.parentElement.appendChild(link);
link.appendChild(subCount);

}

fetch(url).then(response => response.text().then(data => {

let matched = data.match(/var ytInitialData = (\{.*?});/)?.[1];

if (matched) {
try {

const pageData = JSON.parse(matched);
const videosCountText = pageData?.header?.["c4TabbedHeaderRenderer"]?.["videosCountText"]?.["runs"]?.map((entry) => entry.text)?.join("");

if (videosCountText && subCount["textChanged_"] && subCount?.["text"]?.["simpleText"]) {

subCount["textChanged_"]?.({
runs: [
{text: subCount["text"]["simpleText"]},
{text: " ‧ "},
{text: videosCountText},
]
});

const parent = subCount.parentElement;

if (parent?.nodeName === "A") {
parent.title = subCount.textContent;
}

}

} catch (e) {
}
}

}));

};

const update = () => {
if (iridiumSettings.videoCount) {
window.addEventListener("yt-page-data-updated", onEvent, true);
onEvent();
} else {

window.removeEventListener("yt-page-data-updated", onEvent, true);

const subCount = document.getElementById("owner-sub-count");
const link = subCount?.parentElement;

if (link?.nodeName === "A") {
link?.parentElement?.appendChild(subCount);
link?.remove();
}

if (subCount?.["textChanged_"] && subCount?.["text"]?.["simpleText"]) {
subCount["textChanged_"]?.({
runs: [
{text: subCount["text"]["simpleText"]},
]
});
}

}
};

FeatureUpdater.register(SettingData.videoCount.id, update);

return {};

})();

const FeatureInfoCards = (() => {

const listener = data => {
Expand Down
4 changes: 4 additions & 0 deletions src/chrome/js/chrome-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
id: "creatorMerch",
default: true,
},
videoCount: {
id: "videoCount",
default: true,
},
superTheater: {
id: "superTheater",
default: true,
Expand Down
4 changes: 4 additions & 0 deletions src/chrome/js/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const SettingData = {
id: "creatorMerch",
default: true,
},
videoCount: {
id: "videoCount",
default: true,
},
superTheater: {
id: "superTheater",
default: true,
Expand Down
17 changes: 17 additions & 0 deletions src/chrome/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ const Manager = {

Util.updateSingleSetting(settingId, newState);

},
updateVideoCount: (newState, userInteraction) => {

const settingId = SettingData.videoCount.id;
const ui = document.querySelector(`[data-setting=${settingId}]`);

if (ui != null && ui.checked !== newState) {
ui.checked = newState;
}

if (!userInteraction) return;

Util.updateSingleSetting(settingId, newState);

},
updateSuperTheater: (newState, userInteraction) => {

Expand Down Expand Up @@ -720,6 +734,9 @@ const Util = {
case SettingData.creatorMerch.id:
Manager.updateCreatorMerch(value, userInteraction);
break;
case SettingData.videoCount.id:
Manager.updateVideoCount(value, userInteraction);
break;
case SettingData.superTheater.id:
Manager.updateSuperTheater(value, userInteraction);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/chrome/js/setting-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const SettingData = {
id: "creatorMerch",
default: true,
},
videoCount: {
id: "videoCount",
default: true,
},
superTheater: {
id: "superTheater",
default: true,
Expand Down
10 changes: 10 additions & 0 deletions src/firefox/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@
<div class="settingDescription">Allows the creator merch to be shown below the video details</div>
</div>
</div>
<div class="setting" data-id="videoCount">
<label class="switch">
<input data-setting="videoCount" type="checkbox">
<span class="slider"></span>
</label>
<div class="settingDescription">
<div class="settingDescription highlight">Linked video count</div>
<div class="settingDescription">Creates a link that shows the number of videos uploaded by the channel next to the subscriber count</div>
</div>
</div>
</div>
</div>
<div class="settingGroup">
Expand Down
103 changes: 103 additions & 0 deletions src/firefox/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,109 @@ function mainScript(extensionId, SettingData, defaultSettings) {

})();

const FeatureVideoCount = (() => {

const onEvent = () => {

const subCount = document.getElementById("owner-sub-count");

if (!subCount) {
return;
}

const channelId = document.getElementById("movie_player")?.["getPlayerResponse"]()?.["videoDetails"]?.["channelId"] || "";

let url = null;

if (channelId.startsWith("UC")) {
url = `/channel/${channelId}`;
} else if (channelId.startsWith("/@")) {
url = channelId;
} else {
return;
}

if (subCount.parentElement.nodeName !== "A") {

const link = document.createElement("a");

link.href = `${url}/videos`;
link.className = "yt-simple-endpoint";

subCount.parentElement.appendChild(link);
link.appendChild(subCount);

}

fetch(url).then(response => response.text().then(data => {

let matched = data.match(/var ytInitialData = (\{.*?});/)?.[1];

if (matched) {
try {

const pageData = JSON.parse(matched);
const videosCountText = pageData?.header?.["c4TabbedHeaderRenderer"]?.["videosCountText"]?.["runs"]?.map((entry) => entry.text)?.join("");

if (videosCountText && subCount["textChanged_"] && subCount?.["text"]?.["simpleText"]) {

subCount["textChanged_"]?.({
runs: [
{text: subCount["text"]["simpleText"]},
{text: " ‧ "},
{text: videosCountText},
]
});

const parent = subCount.parentElement;

if (parent?.nodeName === "A") {
parent.title = subCount.textContent;
}

}

} catch (e) {
}
}

}));

};

const update = () => {
if (iridiumSettings.videoCount) {
window.addEventListener("yt-page-data-updated", onEvent, true);
onEvent();
} else {

window.removeEventListener("yt-page-data-updated", onEvent, true);

const subCount = document.getElementById("owner-sub-count");
const link = subCount?.parentElement;

if (link?.nodeName === "A") {
link?.parentElement?.appendChild(subCount);
link?.remove();
}

if (subCount?.["textChanged_"] && subCount?.["text"]?.["simpleText"]) {
subCount["textChanged_"]?.({
runs: [
{text: subCount["text"]["simpleText"]},
]
});
}

}
};

FeatureUpdater.register(SettingData.videoCount.id, update);

return {};

})();

const FeatureInfoCards = (() => {

const listener = data => {
Expand Down
17 changes: 17 additions & 0 deletions src/firefox/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ const Manager = {

Util.updateSingleSetting(settingId, newState);

},
updateVideoCount: (newState, userInteraction) => {

const settingId = SettingData.videoCount.id;
const ui = document.querySelector(`[data-setting=${settingId}]`);

if (ui != null && ui.checked !== newState) {
ui.checked = newState;
}

if (!userInteraction) return;

Util.updateSingleSetting(settingId, newState);

},
updateSuperTheater: (newState, userInteraction) => {

Expand Down Expand Up @@ -720,6 +734,9 @@ const Util = {
case SettingData.creatorMerch.id:
Manager.updateCreatorMerch(value, userInteraction);
break;
case SettingData.videoCount.id:
Manager.updateVideoCount(value, userInteraction);
break;
case SettingData.superTheater.id:
Manager.updateSuperTheater(value, userInteraction);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/firefox/js/setting-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const SettingData = {
id: "creatorMerch",
default: true,
},
videoCount: {
id: "videoCount",
default: true,
},
superTheater: {
id: "superTheater",
default: true,
Expand Down

0 comments on commit 43d756d

Please sign in to comment.