Dirty Ghost Spellchecker

A solution for spellcheck in Ghost

当前为 2014-10-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Dirty Ghost Spellchecker
  3. // @namespace http://reaves.co/
  4. // @version 0.1
  5. // @description A solution for spellcheck in Ghost
  6. // @match http://*/ghost/editor/*
  7. // @copyright 2014+, Ryan Reaves
  8. // ==/UserScript==
  9.  
  10.  
  11.  
  12. $(document).ready(function(){
  13. executeDirty();
  14. });
  15.  
  16. var checkIt = setInterval(function()
  17. {
  18. console.log($('#spellModal2'));
  19. if(document.getElementById('spellModal') == undefined){
  20. executeDirty();
  21. clearInterval(checkIt);
  22. }
  23. }, 500);
  24.  
  25. function executeDirty(){
  26. var helpLink = document.querySelectorAll('a.markdown-help')[0];
  27. var $floatingHeader = document.querySelectorAll('header.floatingheader')[0];
  28. var $btn = $('<a id="spellModal" href="#" style="float:right" class="rawtext">SPELLCHECK</a>');
  29. $btn.appendTo($floatingHeader);
  30. var textArea;
  31. // define a handler
  32. function doc_keyDown(e) {
  33.  
  34. if (e.altKey && e.keyCode == 70) {
  35. $('#spellModal').trigger('click');
  36. e.preventDefault();
  37. }
  38. else if (e.altKey && e.keyCode == 87) {
  39. // call your function to do the thing
  40. $('a.close').trigger('click');
  41. e.preventDefault();
  42. }
  43. }
  44. // register the handler
  45. document.addEventListener('keydown', doc_keyDown, false);
  46. $btn.on('click', function(e) {
  47. var cpeditor = document.querySelectorAll('div.CodeMirror-code')[0].childNodes[0].childNodes[0].childNodes[0];
  48. textArea = cpeditor.textContent;
  49. //Content area will not highlight spelling mistakes with a space on the end, so I will attach it below
  50. lastChar = textArea.substr(textArea.length - 1);
  51. if(lastChar != " "){
  52. textArea = textArea + " ";
  53. }
  54. //initiate help link, but then override the content in the modal window for spellcheck
  55. helpLink.click();
  56. var spellModal = document.querySelectorAll('header.modal-header')[0];
  57. spellModal.childNodes[0].innerHTML = 'Dirty Ghost SpellCheck';
  58. if(document.getElementById('spellTips') == undefined){
  59. spellModal.childNodes[0].insertAdjacentHTML('afterend','<span id="spellTips" style="float: right; padding-right: 25px">Open - Alt+F | Close - Alt+W</span>');
  60. }
  61. var shortcuts = document.querySelectorAll('section.modal-body')[0];
  62. $(".modal").css("width","75%");
  63. if(shortcuts != undefined){
  64. shortcuts.remove();
  65. }
  66. var txtbox = "1.) When done press [Ctrl+A] & then [Ctrl+C]<br>2.) Close window [Alt+W] and press [Ctrl+A] & [Ctrl+P]<br>Note: Mac Users will use Cmd<br><textarea style='width:100%; max-width:100% !important; height:100%' rows='20' spellcheck='true' id='spellcheck'>"+textArea+"</textarea>";
  67. spellModal.insertAdjacentHTML('afterend',txtbox);
  68. $("#spellcheck").focus();
  69. });
  70.  
  71.  
  72. }