Created
May 26, 2012 09:20
-
-
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.
This file contains 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
// ==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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I posted this user JS in these threads:
Opera displays all sections of a lecture as list item 1:
http://forums.udacity.com/technical-support/questions/210/opera-displays-all-sections-of-a-lecture-as-list-item-1
All bullet list items are labeled as #1 in IE9:
http://forums.udacity.com/technical-support/questions/231/all-bullet-list-items-are-labeled-as-1-in-ie9
Issues with Opera 11.62:
http://forums.udacity.com/technical-support/questions/308/issues-with-opera-1162