Skip to content

Instantly share code, notes, and snippets.

@XP1
Created May 26, 2012 09:20
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 XP1/2793070 to your computer and use it in GitHub Desktop.
Save XP1/2793070 to your computer and use it in GitHub Desktop.
Fix Udacity: Fixes the numbering of the table of contents in the course content tab. Allows settings to be saved by disabling negative event timestamps.
// ==UserScript==
// @name Fix Udacity
// @version 1.01
// @description Fixes the numbering of the table of contents in the course content tab. Allows settings to be saved by disabling negative event timestamps.
// @author XP1 (https://github.com/XP1/)
// @namespace https://gist.github.com/2793070/
// @include http*://udacity.com/*
// @include http*://*.udacity.com/*
// ==/UserScript==
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */
(function (opera, window, Object, Event, HTMLScriptElement)
{
"use strict";
function fixTableOfContentsTemplate()
{
var isReplaced = false;
function replaceTableOfContentsTemplate()
{
if (isReplaced)
{
return;
}
var document = window.document;
var template = document.querySelector("[data-template-name=\"course_toc_template\"]");
if (!(template instanceof HTMLScriptElement))
{
return;
}
var text = template.textContent.replace(/\{\{#view App\.NuggetGroupView groupBinding="this"\}\}/gi, "{{#view App.NuggetGroupView groupBinding=\"this\" tagName=\"li\" classBinding=\"group.active\"}}")
.replace(/<li \{\{bindAttr class="group\.active"\}\}>/gi, "")
.replace(/<\/li>\s*\{\{\/view\}\}/gi, "{{/view}}");
template.textContent = text;
isReplaced = true;
}
opera.addEventListener("BeforeScript", function listener(userJsEvent)
{
if (isReplaced)
{
opera.removeEventListener("BeforeScript", listener, false);
return;
}
replaceTableOfContentsTemplate(userJsEvent);
}, false);
}
function disableEventTimestamp()
{
var hasTimestampBug = ((new Event("")).timeStamp === -2147483648);
if (!hasTimestampBug)
{
return;
}
Object.defineProperty(Event.prototype, "timeStamp", {
get: function getTimestamp()
{
return (new Date()).getTime();
}
});
}
fixTableOfContentsTemplate();
disableEventTimestamp();
}(this.opera, this, this.Object, this.Event, this.HTMLScriptElement));
@XP1
Copy link
Author

XP1 commented May 26, 2012

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