Skip to content

Instantly share code, notes, and snippets.

@iwconfig
Last active January 9, 2018 01:54
Show Gist options
  • Save iwconfig/7ab2ffd0401b56fec86fee05439ea9b6 to your computer and use it in GitHub Desktop.
Save iwconfig/7ab2ffd0401b56fec86fee05439ea9b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from json import dumps
import requests
import re
import sys
import os
# Given the extension url(s) as parameter(s) it downloads the extension(s) to '$HOME/Downloads',
# and creating a .json file in '/usr/share/chromium/extensions'. Next time Chromium starts up,
# it will load the extension(s) automatically.
PY3 = sys.version_info[0] == 3
if PY3:
from urllib.request import urlretrieve
else:
from urllib import urlretrieve
if os.geteuid() != 0:
print 'This will need sudo...'
links = sys.argv[1:]
downloadlink = "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=47.0&x=id%3D{}%26installsource%3Dondemand%26uc"
extensionids = []
regexx = re.compile("http[s]?.+\/(?P<lastpart>.+)")
for link in links:
id = regexx.search(link).group("lastpart")
if '?hl=' in id:
id = id.split('?')[0]
extensionids.append(id)
headers = {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"}
for extensionid in extensionids:
htmldata = requests.get(link, headers=headers).content
name = re.compile('<h1 class="e-f-w">(.+?)</h1>').search(htmldata).group(1)
slugname = re.sub('[^\w\s-]', '-', re.sub('[-\s]+', '-', name)).strip()
version = re.compile('<span class="C-b-p-D-Xe h-C-b-p-D-md">(.+?)</span>').search(htmldata).group(1)
link = downloadlink.format(extensionid)
extensiondownload = requests.get(link,headers=headers).url
urlretrieve(extensiondownload, os.path.expanduser('~') + "/Downloads/{}_v{}.crx".format(slugname, version))
print extensionid
jsondir = '/usr/share/chromium/extensions/'
jsonfilename = '{}{}.json'.format(jsondir, extensionid)
if not os.path.exists(jsondir):
os.system('sudo mkdir ' + jsondir)
os.system('sudo touch ' + jsonfilename)
os.system('sudo chmod 777 ' + jsonfilename)
with open(jsonfilename, 'w+') as f:
jsondata = {'external_version': version, 'external_crx': '/home/fivethous/Downloads/{}_v{}.crx'.format(slugname, version)}
f.write(dumps(jsondata, indent=4, sort_keys=True))
f.truncate()
f.close()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Not really necessary since i solved it like a PIECE OF CAKE! when i found the 'Global New Tab Shortcut' chrome extension.
# Sigh. Anyway, here it is. There is some delay when using this so its not very handy in my opinion,
# but this can be used as an example for someting else.
###
import subprocess
id = subprocess.check_output(['/usr/bin/xdotool', 'getwindowfocus'])
window = subprocess.check_output(['/usr/bin/xdotool', 'getwindowname', id])
if window.find(' – Chromium') != -1:
subprocess.call(['/usr/bin/xdotool', 'windowraise', id, 'key', 'alt+F4'])
exit

Dependencies for installing ungoogled-chromium from source.

Might be useful someday, but i guess i should update the list. At least in the far future.

build-essential:native clang-3.8 debhelper ninja-build python-jinja2 flex yasm xvfb wdiff gperf bison valgrind libglew-dev libgl1-mesa-dev libglu1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev mesa-common-dev libxt-dev libre2-dev libgbm-dev libpng-dev libxss-dev libelf-dev libvpx-dev libpci-dev libcap-dev libdrm-dev libicu-dev libffi-dev libkrb5-dev libexif-dev libudev-dev libopus-dev libwebp-dev libxtst-dev libsrtp-dev libjpeg-dev libxml2-dev libgtk-3-dev libxslt1-dev libpulse-dev libpam0g-dev libsnappy-dev libgconf2-dev libavutil-dev libavcodec-dev libavformat-dev libglib2.0-dev libasound2-dev libsqlite3-dev libjsoncpp-dev libspeechd-dev libminizip-dev libhunspell-dev libharfbuzz-dev libusb-1.0-0-dev libmodpbase64-dev libgnome-keyring-dev libnss3-dev libnspr4-dev libcups2-dev libevent-dev libjs-jquery libjs-excanvas libjs-jquery-flot libgcrypt20-dev
#!/usr/bin/python
# Not really necessary since i solved it like a PIECE OF CAKE! when i found the 'Global New Tab Shortcut' chrome extension.
# Sigh. Anyway, here it is. There is some delay when using this so its not very handy in my opinion,
# but this can be used as an example for someting else.
# Never mind the commented parts below this text.
#from subprocess import check_output, Popen, call, PIPE
import webbrowser
webbrowser.get('chromium').open_new_tab('https://start.duckduckgo.com/')
#window = Popen(['/usr/bin/xdotool', 'search', '--desktop', '0', '--class', 'chromium'], stdout=PIPE)
#window = window.communicate()[0]
#print 'JAHAp' + window
#if window:
# window = window.split('\n')[-2]
## if window.isdigit():
# call(['/usr/bin/xdotool', 'windowraise', window, 'key', 'ctrl+t'])
# print 'NEEEEW TAAAAB'
#else:
# n = Popen(['chromium', '&'])
# print 'NEEEW WIIINDOOOOW'
Chromebook Search key shortcut to open startmenu. (i.e. 'xfce4-popup-whiskermenu')
Alternatively 'xfce4-popup-applicationsmenu', 'xfce4-appfinder' or 'xfce4-appfinder --collapsed'
xfconf-query --create --channel xfce4-keyboard-shortcuts --property '/commands/custom/Overlay1_Enable' --type string --set 'xfce4-popup-whiskermenu'
Start Chromium browser / open new window with Ctrl+Alt+C.
While running, Ctrl+N works aswell, even a little smoother (native global shortcut).
xfconf-query --create --channel xfce4-keyboard-shortcuts --property '/commands/custom/<Primary><Alt>c' --type string --set 'chromium'
#!/usr/bin/env bash
notify-send -t 8000 --icon=info "$(xsel -o)" \
"$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=sv&dt=t&q=$(xsel -o)" | cut -d"\"" -f2)"
## Use with xfce4-keyboard-shortcuts. The command below binds Shift+Ctrl+Alt+T to this script (which in this case is located in /home/USER/Scripts)
## xfconf-query --create --channel xfce4-keyboard-shortcuts --property '/commands/custom/<Primary><Shift><Alt>t' --type string --set $HOME'/Scripts/TranslateAndNotify.sh'
## Select word(s) or sentence(s), hit the shortcut and you the translation as a notification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment