|
2 | 2 | // @name Github.com - Add RPG tab
|
3 | 3 | // @namespace nitlanguage/github/rpg
|
4 | 4 | // @description Adds a "Github RPG" Tab at the end of the tabs.
|
5 |
| -// @include https://github.com/nitlang/nit* |
6 |
| -// @version 1 |
| 5 | +// @include https://github.com/* |
| 6 | +// @downloadURL https://github.com/nitlang/nit/raw/master/contrib/nitrpg/nitrpg.user.js |
| 7 | +// @version 2 |
7 | 8 | // @grant none
|
8 | 9 | // ==/UserScript==
|
9 | 10 |
|
10 |
| -/* This script is a userscript to use in browsers with the appropriate plug-in to add a "RPG" tab on the github site. |
11 |
| -*/ |
12 |
| - |
13 |
| -/* TODO: |
14 |
| - * Link to the player page (if logged and is a player) |
15 |
| - * Link to other games (not just `nitlang/nit` but other) |
16 |
| -*/ |
17 |
| - |
18 | 11 | // The nav bar with tabs
|
19 |
| -var nav = document.getElementsByClassName('repo-nav'); |
| 12 | +var nav = document.getElementsByClassName('reponav'); |
| 13 | +if (!nav || !nav[0]) return; |
20 | 14 |
|
21 |
| -// The new tab |
22 |
| -var html = '<li class="tooltipped tooltipped-w" aria-label="Github RPG">\ |
23 |
| - <a href="http://nitlanguage.org/rpg/games/nitlang/nit" aria-label="RPG" class="js-selected-navigation-item sunken-menu-item" data-selected-links="repo_settings /nitlang/nit/settings">\ |
24 |
| - <span class="octicon octicon-ruby"></span> <span class="full-word">Github RPG</span>\ |
25 |
| - <img alt="" class="mini-loader" height="16" src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif" width="16">\ |
26 |
| -</a></li>'; |
| 15 | +// The current repo to link |
| 16 | +var repo = $("meta[name='octolytics-dimension-repository_nwo']").attr("content"); |
| 17 | +//repo = "nitlang/nit"; |
| 18 | +if (!repo) return; |
27 | 19 |
|
28 |
| -// Create a new list to put the new tab |
29 |
| -var group = document.createElement('ul'); |
30 |
| -group.setAttribute( 'class', 'sunken-menu-group' ); |
31 |
| -group.innerHTML = html; |
| 20 | +// The content of the new tab |
| 21 | +var html = '<a href="http://nitlanguage.org/rpg/games/' + repo + '" class="js-selected-navigation-item reponav-item" data-selected-links="nitrpg"><span class="octicon octicon-ruby"></span> Github RPG</a>'; |
| 22 | +//html = '<p><span>x</span></p>'; |
32 | 23 |
|
33 |
| -nav[0].appendChild(group); |
| 24 | +// Inject the new tab |
| 25 | +var div = document.createElement('div'); |
| 26 | +div.innerHTML = html; |
| 27 | +nav[0].append(div.firstChild); |
0 commit comments