Improved Tag Popup v0.2
This commit is contained in:
parent
85c6df87d2
commit
0f953e74cd
3 changed files with 49 additions and 4 deletions
18
improved-tag-popup/README.md
Normal file
18
improved-tag-popup/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Improved Tag Popup
|
||||
|
||||
Inspired by [this feature request by Andrew Leach](https://meta.stackexchange.com/q/314150/295232),
|
||||
this script adds some extra links in the new tag popup,
|
||||
to view and edit the full tag information (wiki and excerpt).
|
||||
|
||||
![](example.png)
|
||||
|
||||
## Installation
|
||||
|
||||
- Install the userscript with
|
||||
[this direct link](https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/improved-tag-popup/improved-tag-popup.user.js).
|
||||
|
||||
<sub>developed & tested with Violentmonkey on Firefox</sub>
|
||||
|
||||
## Support
|
||||
|
||||
If you have any questions, please post a comment on [this Stack Apps question](https://stackapps.com/q/8054/34061).
|
BIN
improved-tag-popup/example.png
Normal file
BIN
improved-tag-popup/example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
|
@ -5,7 +5,7 @@
|
|||
// @author Glorfindel
|
||||
// @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/improved-tag-popup/improved-tag-popup.user.js
|
||||
// @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/improved-tag-popup/improved-tag-popup.user.js
|
||||
// @version 0.1
|
||||
// @version 0.2
|
||||
// @match *://*.stackexchange.com/*
|
||||
// @match *://*.stackoverflow.com/*
|
||||
// @match *://*.superuser.com/*
|
||||
|
@ -17,14 +17,41 @@
|
|||
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
|
||||
// ==/UserScript==
|
||||
|
||||
// from https://stackoverflow.com/a/21249710/4751173
|
||||
$.fn.ownText = function() {
|
||||
return this.eq(0).contents().filter(function() {
|
||||
return this.nodeType === 3 // && $.trim(this.nodeValue).length;
|
||||
}).map(function() {
|
||||
return this.nodeValue;
|
||||
}).get().join('');
|
||||
}
|
||||
|
||||
waitForKeyElements("div.tag-popup", function(jNode) {
|
||||
jNode.find("a").filter(function() {
|
||||
return $(this).text() === "View tag";
|
||||
}).each(function() {
|
||||
let tagName = $(this).attr("href").split("/").pop();
|
||||
let hasInfo = $(this).parent().ownText().trim().length > 0;
|
||||
if (hasInfo) {
|
||||
$("<br/>").insertBefore($(this));
|
||||
}
|
||||
|
||||
// Other questions
|
||||
$(this).text("Other questions");
|
||||
var tagName = $(this).attr("href").split("/").pop();
|
||||
$("<br/>").insertBefore($(this));
|
||||
$("<a href=\"/tags/" + tagName + "/info\">More info</a>").insertBefore($(this));
|
||||
|
||||
// More info
|
||||
let infoURL = "/tags/" + tagName + "/info";
|
||||
$("<a href=\"" + infoURL + "\">More info</a>").insertBefore($(this));
|
||||
$("<span> | </span>").insertBefore($(this));
|
||||
|
||||
// Edit/add info
|
||||
let editLink = $("<a>" + (hasInfo ? "Edit" : "Add") + " info</a>");
|
||||
editLink.click(function() {
|
||||
$.get(infoURL, function(data) {
|
||||
window.location.href = $(data).find("a[href^='/edit-tag-wiki/']").attr("href");
|
||||
});
|
||||
});
|
||||
editLink.insertBefore($(this));
|
||||
$("<span> | </span>").insertBefore($(this));
|
||||
});
|
||||
})
|
Loading…
Reference in a new issue