Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jhauga/57f0fe041128b93c13e161587e94e19f to your computer and use it in GitHub Desktop.

Select an option

Save jhauga/57f0fe041128b93c13e161587e94e19f to your computer and use it in GitHub Desktop.
Bookmarklet - use this bookmarklet for when toggling subscription list, and tired of scrolling way up to show less. Ensure to copy/paste the top condensed line of the bookmarklet. Info at "https://github.com/isocialPractice/bookmarklets".
/// *********************************************************** ///
// ****************** BROWSER BOOKMARKLET GIST ***************** //
// ************************************************************* //
// //
// LICENSE /////////////////////////////////////////////////////
// ******* //
// The code in this gist is public domain. //
// Licensed as Public Domain CC0 //
//////////////////////////////////////////////////////////////////
//
// COPY / PAST BELOW LINE TO USE
javascript:(function() { /* Global variables. */ var expandButtonYouTubeTopSubscriptionToggleBtn = /* show more */ document.querySelector('ytd-guide-entry-renderer#expander-item[role="button"]'); var collapseButtonYouTubeTopSubscriptionToggleBtn = /* show less */ document.querySelector('ytd-guide-entry-renderer#collapser-item[role="button"]'); var idYouTubeTopSubscriptionToggleBtn = /* prevent duplicates */ document.getElementById("idYouTubeTopSubscriptionToggleBtn"); /********************************************************************************************* MAIN FUNCTION *********************************************************************************************/ function runYouTubeTopSubscriptionToggleBtn() { if (expandButtonYouTubeTopSubscriptionToggleBtn && !idYouTubeTopSubscriptionToggleBtn) { /* add button */ let clonedButton = document.createElement("button"); let clonedTextA = document.createElement("span"); let clonedTextB = document.createElement("span"); /* mimic current toggle button */ clonedButton.setAttribute("class", "title style-scope ytd-guide-entry-renderer"); clonedButton.setAttribute("style", "background: none; border: none; cursor: pointer"); clonedButton.setAttribute("data-toggle", "0"); clonedButton.setAttribute("id", "idYouTubeTopSubscriptionToggleBtn"); /* add text */ clonedTextA.innerText = "v "; clonedTextB.innerText = "Show More"; clonedTextA.setAttribute("style", "margin-left: 15px; font-family: monospace; " + "font-stretch: extra-expanded;font-weight: bold; font-size: larger;" ); clonedTextB.setAttribute("style", "margin-left: 20px; font-weight: 500"); clonedTextB.setAttribute("id", "idTextYouTubeTopSubscriptionToggleBtn"); clonedButton.insertAdjacentElement("afterbegin", clonedTextA); clonedButton.insertAdjacentElement("beforeend", clonedTextB); /* Attach event listener to the cloned button to trigger the original button's click */ clonedButton.addEventListener('click', () => { if (clonedButton.getAttribute("data-toggle") == "0") { expandButtonYouTubeTopSubscriptionToggleBtn.click(); /* update mimic data */ clonedButton.children[0].innerText = "^ "; clonedButton.children[1].innerText = "Show Less"; /* toggle switch attribute */ clonedButton.setAttribute("data-toggle", "1"); } else { collapseButtonYouTubeTopSubscriptionToggleBtn.click(); /* update mimic data */ clonedButton.children[0].innerText = "v "; clonedButton.children[1].innerText = "Show More"; /* toggle switch attribute */ clonedButton.setAttribute("data-toggle", "0"); } }); /* find the container where you want to insert the new button */ let subscriptions = /* HOT-GLUE - assumes index 0 */ document.getElementsByTagName("ytd-guide-collapsible-section-entry-renderer"); if (subscriptions[0]) { /* insert the cloned button as the first child of ytd-app */ subscriptions[0].insertAdjacentElement("afterbegin", clonedButton); console.log('Duplicated "Show More" button added successfully!'); } else { console.error('Could not find ytd-app element to insert the cloned button.'); } } else { console.error('Original "Show More" button not found.'); } } /* Run bookmarklet. */ runYouTubeTopSubscriptionToggleBtn();})();
// MAKE ANY EDITS AS NEEDED
// *************************************************************
// Use the JS Formatted Bookmarklet below to see if any changes
// need to be made in accordance to the page you want to use
// it for. After making needed changes ensure that the revised
// bookmarklet is condensed before using it in your browser.
// For more info on this bookmarklet visit:
// https://github.com/isocialPractice/bookmarklets
// *************************************************************
// *************************************************************
// ************************JS-FORMATTED*************************
javascript:(function() {
/* Global variables. */
var expandButtonYouTubeTopSubscriptionToggleBtn = /* show more */
document.querySelector('ytd-guide-entry-renderer#expander-item[role="button"]');
var collapseButtonYouTubeTopSubscriptionToggleBtn = /* show less */
document.querySelector('ytd-guide-entry-renderer#collapser-item[role="button"]');
var idYouTubeTopSubscriptionToggleBtn = /* prevent duplicates */
document.getElementById("idYouTubeTopSubscriptionToggleBtn");
/*********************************************************************************************
MAIN FUNCTION
*********************************************************************************************/
function runYouTubeTopSubscriptionToggleBtn() {
if (expandButtonYouTubeTopSubscriptionToggleBtn &&
!idYouTubeTopSubscriptionToggleBtn) {
/* add button */
let clonedButton = document.createElement("button");
let clonedTextA = document.createElement("span");
let clonedTextB = document.createElement("span");
/* mimic current toggle button */
clonedButton.setAttribute("class", "title style-scope ytd-guide-entry-renderer");
clonedButton.setAttribute("style", "background: none; border: none; cursor: pointer");
clonedButton.setAttribute("data-toggle", "0");
clonedButton.setAttribute("id", "idYouTubeTopSubscriptionToggleBtn");
/* add text */
clonedTextA.innerText = "v ";
clonedTextB.innerText = "Show More";
clonedTextA.setAttribute("style",
"margin-left: 15px; font-family: monospace; " +
"font-stretch: extra-expanded;font-weight: bold; font-size: larger;"
);
clonedTextB.setAttribute("style", "margin-left: 20px; font-weight: 500");
clonedTextB.setAttribute("id", "idTextYouTubeTopSubscriptionToggleBtn");
clonedButton.insertAdjacentElement("afterbegin", clonedTextA);
clonedButton.insertAdjacentElement("beforeend", clonedTextB);
/* Attach event listener to the cloned button to trigger the original button's click */
clonedButton.addEventListener('click', () => {
if (clonedButton.getAttribute("data-toggle") == "0") {
expandButtonYouTubeTopSubscriptionToggleBtn.click();
/* update mimic data */
clonedButton.children[0].innerText = "^ ";
clonedButton.children[1].innerText = "Show Less";
/* toggle switch attribute */
clonedButton.setAttribute("data-toggle", "1");
} else {
collapseButtonYouTubeTopSubscriptionToggleBtn.click();
/* update mimic data */
clonedButton.children[0].innerText = "v ";
clonedButton.children[1].innerText = "Show More";
/* toggle switch attribute */
clonedButton.setAttribute("data-toggle", "0");
}
});
/* find the container where you want to insert the new button */
let subscriptions = /* HOT-GLUE - assumes index 0 */
document.getElementsByTagName("ytd-guide-collapsible-section-entry-renderer");
if (subscriptions[0]) {
/* insert the cloned button as the first child of ytd-app */
subscriptions[0].insertAdjacentElement("afterbegin", clonedButton);
console.log('Duplicated "Show More" button added successfully!');
} else {
console.error('Could not find ytd-app element to insert the cloned button.');
}
} else {
console.error('Original "Show More" button not found.');
}
}
/* Run bookmarklet. */
runYouTubeTopSubscriptionToggleBtn();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment