gist fill in fileName automatically

Fill in the filename automatically When pasting a Greasemonkey script.

Verze ze dne 18. 05. 2014. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

  1. // ==UserScript==
  2. // @name gist fill in fileName automatically
  3. // @namespace http://efcl.info/
  4. // @description Fill in the filename automatically When pasting a Greasemonkey script.
  5. // @include http://gist.github.com/
  6. // @include https://gist.github.com/
  7. // @version 0.0.1.20140518104258
  8. // ==/UserScript==
  9.  
  10. /* GRATITUDE
  11. ペーストされたテキストを置き換えるスクリプト
  12. http://gist.github.com/338606
  13. */
  14. var fileExtension = ".user.js";
  15. var addAutoEvent = function(fileID) {
  16. var editArea = document.getElementsByName("file_contents[gistfile" + fileID + "]")[0];
  17. var editFileName = document.getElementsByName("file_name[gistfile" + fileID + "]")[0];
  18. var editDescription = document.getElementsByName("description")[0];
  19. editArea.addEventListener("paste", function(e) {
  20. // この瞬間はまだtargetのvalueが空である。
  21. var obj = e.target;
  22. obj.addEventListener('input', function(evt) {
  23. // クリップボードの内容がinputされた
  24. evt.currentTarget.removeEventListener(evt.type, arguments.callee, false);
  25. var pasteValue = obj.value;
  26. // name
  27. var atName = pasteValue.match(/@name\s+([\w\s]+)/i);
  28. atName = atName && atName[1];
  29. // description
  30. var atDesc = pasteValue.match(/@description\s+(.*)/i);
  31. atDesc = atDesc && atDesc[1];
  32. if (atName && !editFileName.value) {
  33. atName = atName.replace(/\s+$/, "");
  34. // m = m.replace(" " , "_" , "g");// 第3引数 繰り返し
  35. editFileName.value = atName + fileExtension;
  36. // console.log(m + fileExtension);
  37. if(atDesc){
  38. editDescription.value = atDesc;
  39. }
  40. editFileName.focus();
  41. }
  42. }, false);
  43. }, false);
  44. };
  45. // 追加されたテキストエリアにもイベントをつける
  46. var addButton = document.getElementById("add-gist");
  47. addButton.addEventListener("click", function() {
  48. document.getElementById("files").addEventListener("DOMNodeInserted", function(e) {
  49. // テキストエリアが追加された
  50. e.currentTarget.removeEventListener(e.type, arguments.callee, false);
  51. var editAreaLength = document.getElementsByClassName("file").length;
  52. addAutoEvent(editAreaLength);
  53. }, false);
  54. }, false);
  55. // 最初から表示されているテキストエリアにイベントをつける
  56. addAutoEvent(1);