Skip to content

Commit e98f1b5

Browse files
committed
extension
0 parents  commit e98f1b5

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Python Docs Version Switcher extension
2+
3+
This is an extension for Google Chrome that allows you to persistently set the
4+
version on `docs.python.org` to use. For instance, setting it to `3.5` and then
5+
browsing to the docs for `2.7` will automatically redirect you to the version
6+
you specified.
7+
8+
## Installation
9+
10+
Simply download the extension (version 1.0) and run it in chrome:
11+
12+
```bash
13+
$ google-chome python_docs_version_switcher.crx
14+
```
15+
16+
No warranty is given - use at your own risk!
17+
18+
Tested on Google Chrome 44 beta (Linux) but should work anywhere.

python_docs_version_switcher/assets/jquery-2.1.4.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Python Docs Version Switcher</title>
6+
<style>
7+
body {
8+
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
9+
font-size: 0.8em;
10+
}
11+
h1 {
12+
font-size: 1.4em;
13+
}
14+
div.wrapper {
15+
min-width: 300px;
16+
max-width: 400px;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<div class="wrapper">
22+
<h1>Python Docs Version Switcher</h1>
23+
<p>Change version by clicking <a href="https://docs.python.org/" target="_blank">here</a> and selecting a version in the top-left.</p>
24+
</div>
25+
</body>
26+
27+
</html>
28+
4.1 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var url_pattern = new RegExp("docs.python.org/([.0-9]+)/*");
2+
var change_selector = "span.version_switcher_placeholder select";
3+
var storage_key = "preferred_version";
4+
5+
/* Set version of docs from dropdown to local storage and return the
6+
* new value.
7+
*/
8+
function setVersionToStorage()
9+
{
10+
var v = $(change_selector).val();
11+
localStorage.setItem(storage_key, v);
12+
return v;
13+
}
14+
15+
(function() {
16+
var preferred_version, match;
17+
18+
/* Pick up previously set version, or if we haven't set one yet, whatever
19+
* Python redirects us to.
20+
*/
21+
preferred_version = localStorage.getItem("preferred_version");
22+
if (!preferred_version) {
23+
preferred_version = setVersionToStorage();
24+
}
25+
26+
/* Handle changing the version with the version dropdown box */
27+
$(change_selector).change(function() {
28+
preferred_version = setVersionToStorage();
29+
});
30+
31+
/* Check if we are on a non-preferred version of the docs and redirect */
32+
match = url_pattern.exec(window.location);
33+
if (match && match[1] != preferred_version) {
34+
var new_url = window.location.href.replace(match[1], preferred_version);
35+
window.location.replace(new_url);
36+
}
37+
}).call(this);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Python Docs Version Switcher",
4+
"description": "A version switcher for the docs.python.org site",
5+
"version": "1.0",
6+
"icons": {
7+
"128": "assets/python-128x.png"
8+
},
9+
"browser_action": {
10+
"default_popup": "assets/popup.html"
11+
},
12+
"content_scripts": [
13+
{
14+
"matches": ["https://docs.python.org/*"],
15+
"js": ["assets/jquery-2.1.4.min.js", "assets/version_switcher.js"]
16+
}
17+
]
18+
}

0 commit comments

Comments
 (0)