Permalink
Browse files

Misc js projects

  • Loading branch information...
1 parent e5dcef4 commit 3aba4a986e8398c02c5df7aec8dfaddd3d6d712e Tom Robinson committed Sep 30, 2008
Showing with 81 additions and 0 deletions.
  1. +32 −0 misc/jsdump.js
  2. +33 −0 misc/optimize_regex.js
  3. +16 −0 misc/youtube-fullscreen-bookmarklet.js
View
@@ -0,0 +1,32 @@
+
+function pad(n, ch) { var ch = ch || " "; var result = ""; while (n-- > 0) result += ch; return result; }
+
+function dump(obj, stack)
+{
+ if (!stack)
+ stack = [];
+
+ stack.push(obj);
+ for (var i in obj)
+ {
+ if (typeof obj[i] == "object")
+ {
+ var loop = -1;
+ for (var j = 0; j < stack.length; j++) {
+ if (stack[j] === obj[i]) {
+ loop = j;
+ break;
+ }
+ }
+ if (loop < 0) {
+ print(pad(stack.length) + i + " => ");
+ dump(obj[i], stack)
+ } else {
+ print(pad(stack.length) + i + " => [LOOP DETECTED] " + loop);
+ }
+ }
+ else
+ print((pad(stack.length) + i + " => " + obj[i]).substring(0,100).replace(/\n/g, " "));
+ }
+ stack.pop();
+}
View
@@ -0,0 +1,33 @@
+// Takes in an array of strings, returns a regex that matches any of the input strings
+function optimizedRegex(list)
+{
+ var buckets = {};
+ var optional = false;
+
+ for (var i = 0; i < list.length; i++)
+ {
+ var str = list[i];
+ if (!str)
+ optional = true;
+ else
+ {
+ var prefix = str.substring(0, 1);
+ if (!buckets[prefix])
+ buckets[prefix] = [];
+ buckets[prefix].push(str.substring(1))
+ }
+ }
+
+ var ptrns = [];
+ for (var prefix in buckets)
+ ptrns.push(prefix + optimizedRegex(buckets[prefix]));
+
+ if (ptrns.length == 0)
+ return "";
+ if (optional)
+ return "(" + ptrns.join("|") + ")?"
+ else if (ptrns.length > 1)
+ return "(" + ptrns.join("|") + ")"
+ else
+ return ptrns[0];
+}
@@ -0,0 +1,16 @@
+var os = document.getElementsByTagName("object");
+for (var i = 0; i < os.length; i++)
+{
+ var o = os[i].cloneNode(true);
+ o.innerHTML = '<param name="allowFullScreen" value="true"></param>' + o.innerHTML;
+ for (var j = 0; j < o.childNodes.length; j++)
+ {
+ if (o.childNodes[j].name == "movie")
+ o.childNodes[j].value += "&fs=1";
+ else if (o.childNodes[j].nodeName.toUpperCase() == "EMBED") {
+ o.childNodes[j].src += "&fs=1";
+ o.childNodes[j].setAttribute("allowfullscreen", "true");
+ }
+ }
+ os[i].parentNode.replaceChild(o, os[i]);
+}

0 comments on commit 3aba4a9

Please sign in to comment.