Improved Tag Popup v0.2

This commit is contained in:
Glorfindel 2018-09-30 12:09:02 +02:00
parent 85c6df87d2
commit 0f953e74cd
3 changed files with 49 additions and 4 deletions

View 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).

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -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));
});
})