diff --git a/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js b/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js index 7f36c08..00d65a0 100644 --- a/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js +++ b/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js @@ -6,13 +6,13 @@ // @author jerone // @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl) // @license GNU GPLv3 -// @homepage https://github.com/jerone/UserScripts/tree/master/Github_Comment_Enhancer -// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Comment_Enhancer +// @homepage https://github.com/jerone/UserScripts/tree/master/Github_Comment_Enhancer#readme +// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Comment_Enhancer#readme // @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js // @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Comment_Enhancer/Github_Comment_Enhancer.user.js // @supportURL https://github.com/jerone/UserScripts/issues // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW -// @version 2.7.0 +// @version 2.8.0 // @grant none // @run-at document-end // @include https://github.com/* @@ -38,7 +38,7 @@ // Source: https://github.com/gollum/gollum/blob/9c714e768748db4560bc017cacef4afa0c751a63/lib/gollum/public/gollum/javascript/editor/langs/markdown.js var MarkDown = (function MarkDown() { return { - "bold": { + "function-bold": { search: /^(\s*)([\s\S]*?)(\s*)$/g, replace: "$1**$2**$3", shortcut: "ctrl+b" @@ -48,86 +48,122 @@ replace: "$1_$2_$3", shortcut: "ctrl+i" }, - "underline": { + "function-underline": { search: /^(\s*)([\s\S]*?)(\s*)$/g, replace: "$1$2$3", shortcut: "ctrl+u" }, - "strikethrough": { + "function-strikethrough": { search: /^(\s*)([\s\S]*?)(\s*)$/g, replace: "$1~~$2~~$3", shortcut: "ctrl+s" }, - "h1": { + "function-h1": { search: /(.+)([\n]?)/g, replace: "# $1$2", forceNewline: true, shortcut: "ctrl+1" }, - "h2": { + "function-h2": { search: /(.+)([\n]?)/g, replace: "## $1$2", forceNewline: true, shortcut: "ctrl+2" }, - "h3": { + "function-h3": { search: /(.+)([\n]?)/g, replace: "### $1$2", forceNewline: true, shortcut: "ctrl+3" }, - "h4": { + "function-h4": { search: /(.+)([\n]?)/g, replace: "#### $1$2", forceNewline: true, shortcut: "ctrl+4" }, - "h5": { + "function-h5": { search: /(.+)([\n]?)/g, replace: "##### $1$2", forceNewline: true, shortcut: "ctrl+5" }, - "h6": { + "function-h6": { search: /(.+)([\n]?)/g, replace: "###### $1$2", forceNewline: true, shortcut: "ctrl+6" }, - "link": { + "function-link": { exec: function(button, selText, commentForm, next) { var selTxt = selText.trim(), isUrl = selTxt && /(?:https?:\/\/)|(?:www\.)/.test(selTxt), - href = window.prompt("Link href:", isUrl ? selTxt : ""), - text = window.prompt("Link text:", isUrl ? "" : selTxt); - if (href) { - next(String.format("[{0}]({1}){2}", text || href, href, (/\s+$/.test(selText) ? " " : ""))); - } + text = isUrl ? "" : selTxt, + href = isUrl ? selTxt : ""; + unsafeWindow.$.GollumDialog.init({ + title: "Insert Link", + fields: [{ + id: "text", + name: "Link Text", + type: "text", + value: text + }, { + id: "href", + name: "URL", + type: "text", + value: href + }], + OK: function(t) { + if (t.href) { + next(String.format("[{0}]({1}){2}", + t.text || t.href, + t.href, (/\s+$/.test(selText) ? " " : ""))); + } + } + }); }, shortcut: "ctrl+l" }, - "image": { + "function-image": { exec: function(button, selText, commentForm, next) { var selTxt = selText.trim(), isUrl = selTxt && /(?:https?:\/\/)|(?:www\.)/.test(selTxt), - href = window.prompt("Image href:", isUrl ? selTxt : ""), - text = window.prompt("Image text:", isUrl ? "" : selTxt); - if (href) { - next(String.format("{2}", text || href, href, (/\s+$/.test(selText) ? " " : ""))); - } + url = isUrl ? selTxt : "", + alt = isUrl ? "" : selTxt; + unsafeWindow.$.GollumDialog.init({ + title: "Insert Image", + fields: [{ + id: "url", + name: "Image URL", + type: "text", + value: url + }, { + id: "alt", + name: "Alt Text", + type: "text", + value: alt + }], + OK: function(t) { + if (t.url) { + next(String.format("{2}", + t.alt || t.url, + t.url, (/\s+$/.test(selText) ? " " : ""))); + } + } + }); }, shortcut: "ctrl+g" }, - "ul": { + "function-ul": { search: /(.+)([\n]?)/g, replace: String.format("{0} $1$2", listCharacter), forceNewline: true, shortcut: "alt+ctrl+u" }, - "ol": { + "function-ol": { exec: function(button, selText, commentForm, next) { var repText = ""; if (!selText) { @@ -145,39 +181,39 @@ }, shortcut: "alt+ctrl+o" }, - "checklist": { + "function-checklist": { search: /(.+)([\n]?)/g, replace: String.format("{0} [ ] $1$2", listCharacter), forceNewline: true, shortcut: "alt+ctrl+t" }, - "code": { + "function-code": { exec: function(button, selText, commentForm, next) { var rt = selText.indexOf("\n") > -1 ? "$1\n```\n$2\n```$3" : "$1`$2`$3"; next(selText.replace(/^(\s*)([\s\S]*?)(\s*)$/g, rt)); }, shortcut: "ctrl+k" }, - "code-syntax": { + "function-code-syntax": { exec: function(button, selText, commentForm, next) { var rt = "$1\n```" + button.dataset.value + "\n$2\n```$3"; next(selText.replace(/^(\s*)([\s\S]*?)(\s*)$/g, rt)); } }, - "blockquote": { + "function-blockquote": { search: /(.+)([\n]?)/g, replace: "> $1$2", forceNewline: true, shortcut: "ctrl+q" }, - "rule": { + "function-rule": { append: String.format("\n{0}\n", lineCharacter), forceNewline: true, shortcut: "ctrl+r" }, - "table": { + "function-table": { append: "\n" + "| Head | Head | Head |\n" + "| :--- | :----: | ----: |\n" + @@ -187,7 +223,7 @@ shortcut: "alt+shift+t" }, - "clear": { + "function-clear": { exec: function(button, selText, commentForm, next) { commentForm.value = ""; next(""); @@ -195,23 +231,23 @@ shortcut: "alt+ctrl+x" }, - "snippets-tab": { + "function-snippets-tab": { exec: function(button, selText, commentForm, next) { next("\t"); } }, - "snippets-useragent": { + "function-snippets-useragent": { exec: function(button, selText, commentForm, next) { next("`" + navigator.userAgent + "`"); } }, - "snippets-contributing": { + "function-snippets-contributing": { exec: function(button, selText, commentForm, next) { next("Please, always consider reviewing the [guidelines for contributing](../blob/master/CONTRIBUTING.md) to this repository."); } }, - "emoji": { + "function-emoji": { exec: function(button, selText, commentForm, next) { next(button.dataset.value); } @@ -219,186 +255,198 @@ }; })(); - var editorHTML = (function editorHTML() { - return '
' + - - '" + o.body + "
"), + o.fields && "object" == typeof o.fields && (a += t.createFieldMarkup(o.fields)), + o.title && "string" == typeof o.title && (n = o.title), + t.markupCreated && (e.facebox ? e(document).trigger("close.facebox") : e("#gollum-dialog-dialog").remove()), + t.markup = t.createMarkup(n, a), + e.facebox ? e(document).bind("reveal.facebox", function() { + o.OK && "function" == typeof o.OK && (t.attachEvents(o.OK), + e(e('#facebox input[type="text"]').get(0)).focus()) + }) : (e("body").append(t.markup), + o.OK && "function" == typeof o.OK && t.attachEvents(o.OK)), + t.show()) + }, + show: function() { + t.markupCreated && (e.facebox ? e.facebox(t.markup) : e.browser.msie ? (e("#gollum-dialog.dialog").addClass("active"), + t.position(), + e("select").css("visibility", "hidden")) : (e("#gollum-dialog.dialog").css("display", "none"), + e("#gollum-dialog-dialog").animate({ + opacity: 0 + }, { + duration: 0, + complete: function() { + e("#gollum-dialog-dialog").css("display", "block"), + t.position(), + e("#gollum-dialog-dialog").animate({ + opacity: 1 + }, { + duration: 500 + }) + } + }))) + }, + position: function() { + var t = e("#gollum-dialog-dialog-inner").height(); + e("#gollum-dialog-dialog-inner").css("height", t + "px").css("margin-top", -1 * parseInt(t / 2)) + } + }; + e.facebox && e(document).bind("reveal.facebox", function() { + e("#facebox img.close_image").remove() + }), + e.GollumDialog = t + })(unsafeWindow.$) + } else { + unsafeWindow.$.GollumEditor.Dialog.createFieldText = unsafeWindow.$.GollumDialog.createFieldText = function(e) { + var t = ""; + return e.name && (t += ""), + t += ''), + t + }; + } + } + /* * to-markdown - an HTML to Markdown converter * Copyright 2011, Dom Christie @@ -1053,6 +1241,7 @@ addToolbar(); addReplyButtons(); } + overrideGollumDialog(); init(); // on pjax; diff --git a/Github_Comment_Enhancer/README.md b/Github_Comment_Enhancer/README.md index 8467eb3..3955592 100644 --- a/Github_Comment_Enhancer/README.md +++ b/Github_Comment_Enhancer/README.md @@ -39,7 +39,7 @@ Every comment field also got a toolbar, consisting of the following buttons: * UserAgent * Contributing message * Emoji -* Clear comment field content (alt+ctrl+x) +* Clear content (alt+ctrl+x) ## Screenshot @@ -60,6 +60,15 @@ Every comment field also got a toolbar, consisting of the following buttons: ## Version History +* **2.8.0** + * Reverted commit 9bf8974 to fix the toolbar on the wiki. + * Included fix for enabling and disabling buttons per language on wiki. + * Also fixes non-working italic button (fixes #83). + * Added clear button back to wiki. + * Moved help button to the right. + * Only execute action when button is not disabled. + * :sparkles: Added dialog when inserting link or image. + * Homepage is now link to userscript readme. * **2.7.0** * Fixed Github's name completion (fixes https://github.com/jerone/UserScripts/issues/81); * Restored using enter key on dropdown menus.