The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.
Have on.js do it for you!
| from django import forms | |
| from myapp.models import Whatzit | |
| class WhatzitForm(forms.ModelForm): | |
| class Meta(object): | |
| model = Whatzit | |
| fields = ('foo', 'bar', 'baz') |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <style> | |
| a { | |
| display: block; | |
| } | |
| a.foo { | |
| background-color: green; | |
| } |
| class assert_raises(object): | |
| """A context manager that asserts a given exception was raised. | |
| >>> with assert_raises(TypeError): | |
| ... raise TypeError | |
| >>> with assert_raises(TypeError): | |
| ... raise ValueError | |
| AssertionError: 'ValueError' not in ['TypeError'] |
| var field = document.getElementById('id_needs_change_comment'); | |
| var maxlength = Number(field.getAttribute('data-maxlength')); | |
| var remaining = document.getElementById('comment-remaining-characters'); | |
| var remainingText = remaining.textContent; | |
| field.addEventListener('keyup', function() { | |
| var remainingChars = maxlength - this.value.length; | |
| remaining.textContent = remainingText.replace('%d', remainingChars); | |
| }, true); |
| (function(d) { | |
| var c = d.querySelector("#watch-discussion"); | |
| c.parentNode.removeChild(c); | |
| })(document); |
| <!DOCTYPE html> | |
| <title>Multitouch Test</title> | |
| <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
| <meta name="apple-mobile-web-app-capable" content="yes"> | |
| <style> | |
| html, body { | |
| background-color: #000; | |
| color: #fff; | |
| height: 100%; |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | |
| <title>Forms!</title> | |
| <style> | |
| input { | |
| display: block; | |
| font-size: 150%; | |
| } |
| window.addEventListener("load", function() { | |
| var ids = document.querySelectorAll("span.card-short-id"); | |
| Array.prototype.forEach.call(ids, function(el) { | |
| el.classList.remove("hide"); | |
| }); | |
| }, false); |
The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.
Have on.js do it for you!
| # I found myself doing this a lot: cd path/<enter>ls<enter> and thought "that's silly". | |
| # Put this in your .bashrc or another file that is sourced (*not* executed) into your | |
| # shell environment. Then you'll have the "lcd" command available. | |
| # Change directory and list contents. | |
| lcd () { | |
| if [ $# -eq 1 ]; then | |
| cd $1 && ls | |
| elif [ $# -eq 2 ]; then | |
| cd $2 && ls $1 |