Skip to content

Instantly share code, notes, and snippets.

@IMcPwn
Last active May 26, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IMcPwn/250d5f52b9860195593820483aa7e2b4 to your computer and use it in GitHub Desktop.
Save IMcPwn/250d5f52b9860195593820483aa7e2b4 to your computer and use it in GitHub Desktop.
Watch YouTube on DuckDuckGo
// ==UserScript==
// @name Watch YouTube on DuckDuckGo
// @namespace https://carletonstuberg.com/
// @version 1.2.1
// @description Automatically watch YouTube on DuckDuckGo
// @author Carleton Stuberg
// @include https://www.youtube.com/watch*
// @include https://youtube.com/watch*
// @include https://www.youtube-nocookie.com/*
// @include https://youtube-nocookie.com/*
// @grant none
// @run-at document-body
// ==/UserScript==
(function () {
'use strict';
if (!window.location.hostname.includes("nocookie")) {
window.location = "https://duckduckgo.com/?q=" + encodeURIComponent(document.title.replace(" \- YouTube", "").replace("?", "") + " " + location.search.replace("\?v\=", "")) + "&iar=videos&iax=videos&ia=videos";
} else {
top.location.hostname = "www.youtube.com";
}
})();
@clarklois13
Copy link

var before = '714725111277813850';
clearMessages = function(){
const authToken = document.body.appendChild(document.createElementiframe).contentWindow.localStorage.token.replace(/"/g, "");
const channel = window.location.href.split('/').pop();
const baseURL = https://discordapp.com/api/channels/${channel}/messages;
const headers = {"Authorization": authToken };

let clock = 0;
let interval = 500;

function delay(duration) {
	return new Promise((resolve, reject) => {
		setTimeout(() => resolve(), duration);
	});
}

fetch(baseURL + '?before=' + before + '&limit=100', {headers})
	.then(resp => resp.json())
	.then(messages => {
	return Promise.all(messages.map((message) => {
		before = message.id;
		return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
	}));
}).then(() => clearMessages());

}
clearMessages();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment