Last active
May 11, 2022 01:06
-
-
Save mickmister/371b7100f534316fe3f69428d78552b0 to your computer and use it in GitHub Desktop.
YouTube Search and Watch History Purge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Tired of YouTube giving you the same recommendations all the time? | |
As it turns out, the recommendations are calculated directly from your search and watch history. | |
Instructions: | |
1. Visit | |
youtube.com/feed/history/search_history | |
or | |
youtube.com/feed/history | |
2. Scroll down on the page so there are many results visible. | |
3. Open up dev tools. | |
4. Select "Sources", then "Snippets" (in the same menu as "Page" on the left). | |
5. Select "+ New snippet". Name the snippet whatever you please. | |
6. Paste this script into the box on the right. Save the script. | |
7. Run the script using the play button on the bottom right. | |
8. Go the console tab and run the command: | |
removeSearch(searchTerm) | |
or | |
removeWatch(searchTerm) | |
depending on which page you are on. Replace "searchTerm" with your search term. | |
9. Go to the other page (search or watch) and do the same with your search term. | |
The script will delete any searches that match the search query or videos that match the title/description. | |
Now the recommendations will no longer use these entries for its algorithm. | |
*/ | |
let searchTerm | |
const ntol = ls => Array.from(ls) | |
const removeEntry = (ls, searchTerm) => { | |
let filteredResults | |
let deleteButtons | |
filteredResults = ls.filter(x => x.textContent.toUpperCase().indexOf(searchTerm.toUpperCase()) > -1) | |
deleteButtons = filteredResults.map(x => x.parentNode.querySelector('button')) | |
deleteButtons.forEach(x => x.click()) | |
return deleteButtons | |
} | |
const removeWatch = searchTerm => { | |
let matchingTitles | |
let matchingDescriptions | |
matchingTitles = ntol(document.querySelectorAll('h3.title-and-badge')) | |
removeEntry(matchingTitles, searchTerm) | |
matchingDescriptions = ntol(document.querySelectorAll('#description-text')) | |
removeEntry(matchingDescriptions, searchTerm) | |
return {matchingTitles, matchingDescriptions} | |
} | |
const removeSearch = searchTerm => { | |
let searchList | |
searchList = ntol(document.querySelectorAll('a.ytd-search-history-query-renderer')) | |
removeEntry(searchList, searchTerm) | |
return searchList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment