Skip to content

Instantly share code, notes, and snippets.

@tomdwaggy
Last active August 29, 2015 14:05
Show Gist options
  • Save tomdwaggy/4d1d317a0b5550c8f784 to your computer and use it in GitHub Desktop.
Save tomdwaggy/4d1d317a0b5550c8f784 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Example from http://stackoverflow.com/q/6834930
// @version 1.3
// @namespace http://stackoverflow.com/q/6834930
// @description Allow reverse playlist in Youtube
// @include https://www.youtube.com/*
// ==/UserScript==
function load(url, onLoad, onError) {
e = document.createElement("script");
e.setAttribute("src", url);
if (onLoad != null) { e.addEventListener("load", onLoad); }
if (onError != null) { e.addEventListener("error", onError); }
document.head.appendChild(e);
return e;
}
function execute(functionOrCode) {
if (typeof functionOrCode === "function") {
code = "(" + functionOrCode + ")();";
} else {
code = functionOrCode;
}
e = document.createElement("script");
e.textContent = code;
document.head.appendChild(e);
return e;
}
function loadAndExecute(url, functionOrCode) {
load(url, function() { execute(functionOrCode); });
}
loadAndExecute("//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", function() {
console.log("New script loaded...");
// console.log($(".playlist-videos-list"));
$(document).ready(function() {
$(".playlist-videos-list>li").each(function() {
$(element).attr('data-index', 0);
});
console.log($(".playlist-videos-list>li"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment