summaryrefslogtreecommitdiff
path: root/.uzbl/scripts
diff options
context:
space:
mode:
Diffstat (limited to '.uzbl/scripts')
-rwxr-xr-x.uzbl/scripts/adblock.py86
-rwxr-xr-x.uzbl/scripts/downloadviewer.sh7
-rwxr-xr-x.uzbl/scripts/goup.pl24
-rwxr-xr-x.uzbl/scripts/mytest.sh14
-rwxr-xr-x.uzbl/scripts/ytdl.sh8
5 files changed, 115 insertions, 24 deletions
diff --git a/.uzbl/scripts/adblock.py b/.uzbl/scripts/adblock.py
new file mode 100755
index 0000000..aae39f4
--- /dev/null
+++ b/.uzbl/scripts/adblock.py
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+import os
+from sys import argv
+from urlparse import urlparse
+
+# This is the original adblock.py script from http://www.uzbl.org/wiki/adblock
+# Nothing was modified. This script is here just to have everything at one place.
+
+def xdghome(key, default):
+ '''Attempts to use the environ XDG_*_HOME paths if they exist otherwise
+ use $HOME and the default path.'''
+
+ xdgkey = "XDG_%s_HOME" % key
+ if xdgkey in os.environ.keys() and os.environ[xdgkey]:
+ return os.environ[xdgkey]
+
+ return os.path.join(os.environ['HOME'], default)
+
+# Setup xdg paths.
+DATA_DIR = os.path.join(xdghome('DATA', '.local/share/'), 'uzbl/')
+
+# Blockfile location.
+BLOCKFILE = os.path.join(DATA_DIR, 'adblock')
+
+JAVASCRIPT = ' '.join(filter(None, map(str.strip, '''
+var uzblAdBlock = function() {
+ var toblock = %s;
+ for(var n = 0; n < toblock.length; n++) {
+ var items;
+ while (1) {
+ try {
+ items = document.evaluate(toblock[n], document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
+ if (items == null) { break; }
+ var i = items.iterateNext();
+ if (i == null) { break; }
+ i.parentNode.removeChild(i);
+ } catch (e) {
+ break;
+ }
+ }
+ }
+};
+'''.split('\n'))))
+
+
+def get_domain(url):
+ '''Return domain segment of url.'''
+
+ if not url.startswith('http'):
+ url = "http://%s" % url
+
+ loc = urlparse(url).netloc
+ if loc.startswith('www.'):
+ loc = loc[4:]
+
+ return loc
+
+
+def adblock(url, fifo):
+ fh = open(BLOCKFILE, 'r')
+ lines = [line.strip() for line in fh.readlines()]
+ fh.close()
+
+ rules, capture = [], False
+ for l in lines:
+ if not l: # newline splits section
+ capture = False
+
+ elif l[0] == '#':
+ continue
+
+ elif capture:
+ rules.append(l)
+
+ elif l[-1] == ':':
+ if get_domain(l[:-1]) == url or l[:-1] == "global":
+ capture = True
+
+ rulestr = repr(rules).replace("@", "\@")
+ js = "js %s\n" % (JAVASCRIPT % rulestr)
+ fh = open(fifo, "w")
+ fh.write(js)
+ fh.close()
+
+if __name__ == '__main__':
+ adblock(get_domain(argv[6]), argv[4])
diff --git a/.uzbl/scripts/downloadviewer.sh b/.uzbl/scripts/downloadviewer.sh
new file mode 100755
index 0000000..306460d
--- /dev/null
+++ b/.uzbl/scripts/downloadviewer.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+case "$1" in
+*.pdf*) zathura "$1" & ;;
+*.jpg*|*.png*|*.jpeg*) feh "$1" & ;;
+*.txt*|*README*|*.pl*|*.sh*|*.py*|*.hs*|*.hl*) urxvt -e vim "$1" & ;;
+*.mov*|*.avi*|*.mpeg*|*.mpg*|*.flv*|*.wmv*|*.mp4*) mplayer "$1" & ;;
+esac
diff --git a/.uzbl/scripts/goup.pl b/.uzbl/scripts/goup.pl
deleted file mode 100755
index f7ae275..0000000
--- a/.uzbl/scripts/goup.pl
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/perl
-
-my ($config,$pid,$xid,$fifo,$socket,$url,$title,$cmd) = @ARGV;
-if($fifo eq "") { die "No fifo"; };
-
-# Delete last slash
-chop($url);
-
-my $index = index(reverse($url), '/');
-
-# if youre already on top of the directory structure
-if ($index == -1)
-{
- print $url;
- exit;
-}
-
-# Workaround for missing reverse index
-$url = (substr(reverse($url), $index, length($url) ));
-$url = reverse($url);
-print $url."\n";
-
-# This could look prettier with native fifo access
-qx(echo "act uri $url" >> $fifo);
diff --git a/.uzbl/scripts/mytest.sh b/.uzbl/scripts/mytest.sh
new file mode 100755
index 0000000..f310e49
--- /dev/null
+++ b/.uzbl/scripts/mytest.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+
+>> "$UZBL_BOOKMARKS_FILE" || exit 1
+
+which zenity >/dev/null 2>&1 || exit 2
+
+tags="$( zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:" )"
+exitstatus="$?"
+[ "$exitstatus" -eq 0 ] || exit "$exitstatus"
+
+# TODO: check if already exists, if so, and tags are different: ask if you want to replace tags
+echo "$UZBL_URI $tags" >> "$UZBL_BOOKMARKS_FILE"
diff --git a/.uzbl/scripts/ytdl.sh b/.uzbl/scripts/ytdl.sh
new file mode 100755
index 0000000..acf327a
--- /dev/null
+++ b/.uzbl/scripts/ytdl.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+cd ~/Downloads # change this line to determine where the file is saved
+python2 youtube-dl -o %\(title\)s.%\(ext\)s "$1" # -o output template is optional
+# play with mplayer after download
+savename=`python2 youtube-dl -o %\(title\)s.%\(ext\)s --get-filename "$1"`
+mplayer -really-quiet "$savename"
+ratpoison -c "echo [ytdl-uzbl] $1 done." # change this line to change how you are notified of a
+ # completed download