Python User JS Switcher for Opera

Inspired by the Opera Python Adblocker, I have written a script that allows you to enable/disable Opera User JS files on the fly.

Installation: Python

Download and install Python. No configuration needed.

Installation: Script

[Authors: HermeN]
Change JS_PATH in the following script to the correct path to your User JS directory (backslashes in PATH should be double), then save it as a text file with the .py extension:

# Opera JS switcher
#
# Author:  Hermen Toersche
# Date:    18-04-2005

### Imports

import os

### Constants

# Your JS Path, including trailing '\'.
JS_PATH = "C:\\Program Files\\Opera\\profile\\User JS\\"

COMMON_EXT = ".js"
DISABLED_EXT = ".js.disabled"

### Methods

def isEnabled(filenaam):
	return filenaam.endswith(COMMON_EXT)

def isDisabled(filenaam):
	return filenaam.endswith(DISABLED_EXT)

def mooieNaam(filenaam):
	return filenaam.replace(DISABLED_EXT, "").replace(COMMON_EXT, "")

def actLight(filenaam):
	if isEnabled(filenaam):
	    return ">>"
	else:
	    return "  "

def switchState(filenaam):
	if filenaam.endswith(COMMON_EXT):
	    nieuweFilenaam = filenaam[:len(filenaam)-len(COMMON_EXT)] + DISABLED_EXT
	else:
	    nieuweFilenaam = filenaam[:len(filenaam)-len(DISABLED_EXT)] + COMMON_EXT

	os.rename(JS_PATH + filenaam, JS_PATH + nieuweFilenaam)

### Main

print "Opera User JS switcher"
print "++++++++++++++++++++++"

welke = 1
while welke > -1:
	# Find User JS files
	js_files = os.listdir(JS_PATH)

	# Strip non-COMMON/DISABLED
	ok_files = []
	for js_file in js_files:
	    # if complies: add
	    if isEnabled(js_file) or isDisabled(js_file):
	        ok_files.append(js_file)

	print ""

	for i in range(0, len(ok_files)):
	    js_file = ok_files[i]
	    print "%s%3d. " % (actLight(js_file), (i+1)) + mooieNaam(js_file)

	# Input welke JS het over het gaat, en togglet deze.

	print ""
	welke = input("Switch [1-%d], 0=exit: " % len(ok_files))
	welke = welke - 1
	if welke > -1:
	    switchState(ok_files[welke])

Linux-specific Information

On Linux, you should add

#!/usr/bin/python

as the first line and use single slashes in JS_PATH:

JS_PATH="/PATH/"

Installation: Menu Command

The following button can be used to get one-click access to the User JS switcher (the path needs to be adjusted to your setup):

User JS Switcher

You can place „opera_jsswitcher.py“ to Opera folder, and use this button:

User JS Switcher

There is one comment on this page. [Display and/or add comments]