contentdb/app/public/static/package_edit.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

// @author rubenwardy
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
$(function() {
$("#type").change(function() {
$(".not_mod, .not_game, .not_txp").show()
$(".not_" + this.value.toLowerCase()).hide()
})
$(".not_mod, .not_game, .not_txp").show()
$(".not_" + $("#type").val().toLowerCase()).hide()
$("#forums").on('paste', function(e) {
try {
2020-12-04 03:34:08 +01:00
const pasteData = e.originalEvent.clipboardData.getData('text');
const url = new URL(pasteData);
if (url.hostname == "forum.minetest.net") {
$(this).val(url.searchParams.get("t"));
e.preventDefault();
}
} catch (e) {
console.log("Not a URL");
}
});
2018-12-27 01:03:16 +01:00
2020-12-10 00:59:31 +01:00
$("#forums-button").click(function(e) {
window.open("https://forum.minetest.net/viewtopic.php?t=" + $("#forums").val(), "_blank");
});
2018-12-29 16:57:16 +01:00
let hint = null;
function showHint(ele, text) {
if (hint) {
hint.remove();
}
hint = ele.parent()
.append(`<div class="alert alert-warning my-3">${text}</div>`)
.find(".alert");
}
let hint_mtmods = `Tip:
Don't include <i>Minetest</i>, <i>mod</i>, or <i>modpack</i> anywhere in the short description.
It is unnecessary and wastes characters.`;
let hint_thegame = `Tip:
It's obvious that this adds something to Minetest,
there's no need to use phrases such as \"adds X to the game\".`
2019-01-29 04:00:01 +01:00
$("#short_desc").on("change paste keyup", function() {
2020-12-04 03:34:08 +01:00
const val = $(this).val().toLowerCase();
2018-12-29 16:57:16 +01:00
if (val.indexOf("minetest") >= 0 || val.indexOf("mod") >= 0 ||
val.indexOf("modpack") >= 0 || val.indexOf("mod pack") >= 0) {
showHint($(this), hint_mtmods);
} else if (val.indexOf("the game") >= 0) {
showHint($(this), hint_thegame);
} else if (hint) {
hint.remove();
hint = null;
}
})
2020-12-04 03:34:08 +01:00
const btn = $("#forums").parent().find("label").append("<a class='ml-3 btn btn-sm btn-primary'>Open</a>");
2018-12-27 01:03:16 +01:00
btn.click(function() {
2020-12-04 03:34:08 +01:00
const id = $("#forums").val();
2018-12-27 01:03:16 +01:00
if (/^\d+$/.test(id)) {
window.open("https://forum.minetest.net/viewtopic.php?t=" + id, "_blank");
}
});
})