From 7ca61f073f215214bcd997408a8a4b4b0c37705e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 18 Oct 2017 10:56:40 +0200 Subject: Add surf configuration --- config/i3/config | 1 + install | 6 ++ local/bin/surf-menu | 43 +++++++++++ surf/script.js | 186 ++++++++++++++++++++++++++++++++++++++++++++++++ surf/styles/default.css | 0 5 files changed, 236 insertions(+) create mode 100755 local/bin/surf-menu create mode 100644 surf/script.js create mode 100644 surf/styles/default.css diff --git a/config/i3/config b/config/i3/config index 430993e..509d182 100644 --- a/config/i3/config +++ b/config/i3/config @@ -25,6 +25,7 @@ floating_modifier $mod # start a terminal bindsym $mod+Return exec urxvt bindsym $mod+Shift+Return exec conkeror & pidgin +bindsym $mod+Shift+d exec surf-menu # kill focused window bindsym $mod+q kill diff --git a/install b/install index 6123f9a..751760c 100755 --- a/install +++ b/install @@ -105,6 +105,12 @@ if ask "Install Conkeror configuration"; then inst conkeror/ ~/.conkeror fi +if ask "Install Surf configuration"; then + inst surf/script.js ~/.surf/script.js + inst surf/theme/default.css ~/.surf/theme/default.css + inst local/bin/surf-menu ~/.local/bin/surf-menu +fi + if ask "Install MPD configuration"; then inst config/mpd/ ~/.config/mpd fi diff --git a/local/bin/surf-menu b/local/bin/surf-menu new file mode 100755 index 0000000..bd13e6b --- /dev/null +++ b/local/bin/surf-menu @@ -0,0 +1,43 @@ +#!/bin/sh +set -e + +BOOKMARDS=~/notes/bookmarks.md + +# Note: Bookmarks starts with '* ' +sed -n 's/\* //p' "$BOOKMARDS" | dmenu -p 'surf' | while read L; do + if echo "$L" | grep -qE '^\?'; then # We do search on duckduckgo + + surf "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web" + + else # We follow address + + LPROTOCOL="$(echo "$L" | sed -n 's#^\([^:]*\)://.*#\1#p')" + LHOST="$(echo "$L" | sed -n 's#^[^:]*://##;s#^\([^/]\+\)/\?.*#\1#p')" + LPATH="$(echo "$L" | sed 's#^[^:]*://##;s#^[^/]\+/\?##')" + + # Try to lookup if it's an real address + # Note: This is hack because of youtube, nslookup return No answer but + # exists with 0. So I am checking if it returned more than one address + # (one address is for dns server). + if [ "$(nslookup "$LHOST" | grep 'Address:' | wc -l)" -le 1 ]; then # It's a real address + if nslookup "$LHOST.cz" >/dev/null; then # we can expand it with cz + LHOST="$LHOST.cz" + elif nslookup "$LHOST.com" >/dev/null; then # we can expand it with com + LHOST="$LHOST.com" + fi + # TODO what to do when we can't expand it? + fi + # Decide on protocol (if connection to 443 is not possible then use http otherwise https) + if [ -z "$LPROTOCOL" ]; then # We already have protocol (given explicitly) + if nc -z -w1 "$LHOST" 443 2>/dev/null; then + LPROTOCOL="https" + else + LPROTOCOL="http" + fi + fi + + surf "$LPROTOCOL://$LHOST/$LPATH" & # run backgrounded + + fi + +done diff --git a/surf/script.js b/surf/script.js new file mode 100644 index 0000000..36ff8a6 --- /dev/null +++ b/surf/script.js @@ -0,0 +1,186 @@ + +// Easylinks (inspired but my own implementation) +var elink_modkey = 18; //ctrl=17, alt=18 +var elink_copykey = 67; // c +var elink_newwinkey = 84; // t +var elink_openkey = 70; // f + +var elink_ankers = {}; +var elink_labels = {}; + +// Creates visual tags on website +elink_create = function() { + // Just to be sure remove any previous one first + elink_remove(); + // Get all a and input elements + elink_ankers = document.getElementsByTagName("a"); + elink_ankers.push.apply( document.getElementsByTagName("input") ); + // For every anker create label + for (var i=0; i=10 : normal integer, + + // globals + var ankers = document.getElementsByTagName("a"); + var labels = new Object(); + var ui_visible = false; + var input = ""; + + // functions + hl=function(t) { + for(var id in labels) { + if (t && id.match("^"+t)==t) + for(var s in hl_style) + labels[id].rep.style[s]=hl_style[s]; + else + for(var s in label_style) + labels[id].rep.style[s]=label_style[s]; + } + } + open_link=function(id, new_win) { + try { + var a = labels[input].a; + if(a && !new_win) window.location.href=a.href; + if(a && new_win) window.open(a.href,a.href); + } catch (e) {} + } + set_ui=function(s) { + var pos = "static"; + ui_visible = true; + if(s == "hidden") { + ui_visible = false; + pos = "absolute"; + input=""; + } + for(var id in labels) { + labels[id].rep.style.visibility=s; + labels[id].rep.style.position=pos; + } + } + base=function(n, b) { + if(b>=10) return n.toString(); + var res = new Array(); + while(n) { + res.push( (n%b +1).toString() ) + n=parseInt(n/b); + } + return res.reverse().join(""); + } + + // main + // create labels + for (var i=0; i