Evernote Web HTML editor

This scripts adds a button to edit the HTML code of a note in Evernote Web

当前为 2016-08-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Evernote Web HTML editor
  3. // @namespace http://andrealazzarotto.com/
  4. // @version 2.2
  5. // @description This scripts adds a button to edit the HTML code of a note in Evernote Web
  6. // @match http://www.evernote.com/Home.action*
  7. // @match https://www.evernote.com/Home.action*
  8. // @copyright 2015, Seb Maynard, Andrea Lazzarotto
  9. // @license Apache License, Version 2.0
  10. // @require http://code.jquery.com/jquery-latest.min.js
  11. // ==/UserScript==
  12.  
  13. /*
  14. This program is a modified version of the Evernote HTML Editor bookmarklet
  15. created by Seb Maynard and released as open source software under the
  16. Apache 2.0 license. You can download the original software here:
  17.  
  18. https://gist.github.com/sebmaynard/8f9f6b33247ab2f4bc85
  19. http://seb.so/html-source-editor-for-evernote-web-a-bookmarklet/
  20. */
  21.  
  22. /*
  23. Copyright 2015 Seb Maynard, Andrea Lazzarotto
  24.  
  25. Licensed under the Apache License, Version 2.0 (the "License");
  26. you may not use this file except in compliance with the License.
  27. You may obtain a copy of the License at
  28.  
  29. http://www.apache.org/licenses/LICENSE-2.0
  30.  
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. */
  37.  
  38. var icon_old = "iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAzUExURUxpcYiIiIiIiExpcYiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiNINviEAAAAQdFJOUwCqZgDdzBEiuzNVRJl3/4jEJrZZAAAAhUlEQVQY05WPwQ7DIAxDDQokAdr5/7+2gVbrusOkWbnwYmwAfiizfqNkj2NVYM/1tvnYN3Rq4/AFWiHNMQSayJIDGUtcg7xmgFHeLmW/XWfWtseSqX80WgL08bDKjD8VP5PoZKKj0DmRQtRt1oEXEqF2QzbGnMirLJQK+4Uiy5erMVIo5QACmwWhG+ikMQAAAABJRU5ErkJggg==";
  39. var icon_new = "iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAMAAAAMs7fIAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAnUExURUxpcQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK/XnHYAAAAMdFJOUwBEuzPMd2aZIt2I7sVV9wMAAABUSURBVBjTpY7bCsAgDEOjzOvy/9+7por6NBg7SmhCWwr8orbThQjkgissrzKGWRhM0luSuHs0uHp8T8k+eNDqp8uoT6OjU24kCpO9kRieYCveE/IBzfcCeIwe7AAAAAAASUVORK5CYII=";
  40.  
  41. var basic_html_formatter = function(code) {
  42. var block_tags = "p|div|ol|ul|li|pre|blockquote|h[1-6]|table|thead|tbody|tr|td";
  43. code = code.replace(new RegExp("([^\n])(<[\/]?("+block_tags+")[^>]*>)", "g"), "$1\n$2");
  44. for (var i = 0; i<2; i++)
  45. code = code.replace(new RegExp("(<[\/]?("+block_tags+")[^>]*>)([^\n])", "g"), "$1\n$3");
  46. return code;
  47. };
  48.  
  49. var getCurrentContent = function() {
  50. var content = $("#tinymce, #en-note", $("iframe").contents()).first().clone();
  51. content.find("*").removeAttr("data-mce-style").removeAttr("data-mce-src").removeAttr("data-mce-href");
  52. return basic_html_formatter(content.html());
  53. };
  54. var setCurrentContent = function(content) {
  55. if(!$("table:has(input)").first().is(":visible")) // Activate the note editing mode again
  56. $("iframe.gwt-Frame").first().contents().find("body").click();
  57. $("#tinymce, #en-note", $("iframe").contents()).first().html(content);
  58. $(".ennote", $("iframe").contents()).first().html(content);
  59. };
  60. var popupTextArea = function() {
  61. var theDiv = $("<div id='html_code_editor'></div>");
  62. theDiv.css({
  63. "z-index": "10000",
  64. "position": "fixed",
  65. "top": "0",
  66. "left": "0",
  67. "right": "0",
  68. "bottom": "0"
  69. });
  70. var theTextArea = $("<div id='html_code_area' />");
  71. theTextArea.css({
  72. "width": "100%",
  73. "height": "100%",
  74. "box-sizing": "border-box",
  75. "outline": 0
  76. });
  77. theTextArea.text(getCurrentContent());
  78. var theButtons = $("<div><input id='btn_reset' type='reset'/><input id='btn_submit' type='submit'/></div>");
  79. theButtons.css({
  80. "z-index": "10001",
  81. "position": "fixed",
  82. "right": "4rem",
  83. "bottom": "2rem"
  84. });
  85. $("input", theButtons).css({
  86. "margin-left": "1.5rem",
  87. "background": "#2dbe60",
  88. "color": "white",
  89. "font-weight": "bold",
  90. "border": 0,
  91. "height": "2.5rem",
  92. "min-width": "8rem",
  93. "display": "inline-block"
  94. });
  95. var theTrick = $("<div><a href='https://lazza.me/EvernotePremium20USD'>Get Evernote Premium for €20 ($22) a year</a></div>");
  96. theTrick.css({
  97. "background": "rgba(0, 0, 0, 0.5)",
  98. "padding": ".5em",
  99. "font-family": "Gotham, sans-serif",
  100. "z-index": "10001",
  101. "position": "fixed",
  102. "left": "4rem",
  103. "bottom": "2rem"
  104. });
  105. $("a", theTrick).css("color", "white");
  106. theDiv.append(theTextArea);
  107. theDiv.append(theButtons);
  108. theDiv.append(theTrick);
  109. $("body").append(theDiv);
  110.  
  111. var editor = ace.edit("html_code_area");
  112. editor.setTheme("ace/theme/tomorrow_night");
  113. editor.getSession().setMode("ace/mode/html");
  114. editor.setOptions({
  115. fontSize: "18px",
  116. wrap: "free",
  117. enableBasicAutocompletion: true,
  118. scrollPastEnd: true,
  119. showPrintMargin: false,
  120. enableSnippets: true,
  121. enableLiveAutocompletion: true
  122. });
  123.  
  124. $("#btn_submit", theButtons).click(function() {
  125. setCurrentContent(editor.getValue());
  126. theDiv.remove();
  127. });
  128. $("#btn_reset", theButtons).click(function() {
  129. theDiv.remove();
  130. });
  131. };
  132.  
  133. var placeButton = function() {
  134. // old Evernote Web
  135. var prev = $("table:has(input)").first().find("td:nth-of-type(9)");
  136. var code = "<td id='html_edit'></td>";
  137. var icon = icon_old;
  138. // new Evernote Web
  139. if(!prev.length) {
  140. prev = $("#gwt-debug-FormattingBar-strikeButton").parent();
  141. code = "<div id='html_edit'></div>";
  142. icon = icon_new;
  143. }
  144. if(!prev.length)
  145. return false;
  146. prev.after(code);
  147. var btn = $("#html_edit");
  148. btn.addClass(prev.attr('class'));
  149. btn.attr("style", prev.attr("style"));
  150. prev.find("div").first().clone().appendTo(btn);
  151. btn.find("input").remove();
  152. btn.find("div").attr("title", "HTML");
  153. btn.find("div").css("background-image", "url('data:image/png;base64,"+icon+"')");
  154. btn.click(popupTextArea);
  155. return true;
  156. };
  157.  
  158. $(document).ready(function() {
  159. $.getScript("https://cdn.rawgit.com/ajaxorg/ace-builds/v1.2.5/src-min-noconflict/ace.js").done(function(){
  160. $.getScript("https://cdn.rawgit.com/ajaxorg/ace-builds/v1.2.5/src-min-noconflict/ext-language_tools.js").done(function(){
  161. // Place the button at the end of the formatting options
  162. setTimeout(function() {
  163. if(!placeButton())
  164. setTimeout(arguments.callee, 400);
  165. }, 400);
  166. });
  167. });
  168. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址