content_probeForSG.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * I am executed by Chromium extension when called from background.js
  3. *
  4. */
  5. (function(){
  6. var scriptsToInject = [
  7. // Libraries
  8. 'libs/SmallClasses.js',
  9. 'libs/wysihtml5/wysihtml5-parser.js',
  10. 'libs/wysihtml5/wysihtml5.js',
  11. 'libs/flexicolorpicker/colorpicker.js',
  12. // SuperGlue classes
  13. 'classes/SuperGlue.js',
  14. 'classes/Clipboard.js',
  15. 'classes/ColorPickerWidget.js',
  16. 'classes/Compiler.js',
  17. 'classes/CreationMenu.js',
  18. 'classes/Document.js',
  19. 'classes/DocumentMenu.js',
  20. 'classes/Element.js',
  21. 'classes/EmbedElement.js',
  22. 'classes/FileManager.js',
  23. 'classes/FileManagerWindow.js',
  24. 'classes/Grid.js',
  25. 'classes/HTMLEditor.js',
  26. 'classes/History.js',
  27. 'classes/IFrameElement.js',
  28. 'classes/ImageElement.js',
  29. 'classes/MenuItem.js',
  30. 'classes/MenuItemBackgroundColor.js',
  31. 'classes/MenuItemBackgroundImg.js',
  32. 'classes/MenuItemBackgroundRepeat.js',
  33. 'classes/MenuItemCenter.js',
  34. 'classes/MenuItemFileManager.js',
  35. 'classes/MenuItemNewPage.js',
  36. 'classes/MenuItemOutlines.js',
  37. 'classes/MenuItemPageTitle.js',
  38. 'classes/MenuItemPaste.js',
  39. 'classes/MenuItemRedo.js',
  40. 'classes/MenuItemSave.js',
  41. 'classes/MenuItemSaveAs.js',
  42. 'classes/MenuItemSaveLocal.js',
  43. 'classes/MenuItemSaveRemote.js',
  44. 'classes/MenuItemServerSettings.js',
  45. 'classes/MenuItemUndo.js',
  46. 'classes/Keyboard.js',
  47. 'classes/ResizeHandles.js',
  48. 'classes/SCGUI.js',
  49. 'classes/SCSystemBrowser.js',
  50. 'classes/Selection.js',
  51. 'classes/SliderWidget.js',
  52. 'classes/Server.js',
  53. 'classes/TextEditor.js',
  54. 'classes/TextElement.js',
  55. 'classes/Widget.js',
  56. 'classes/WidgetBackgroundColor.js',
  57. 'classes/WidgetBorder.js',
  58. 'classes/WidgetBorderColor.js',
  59. 'classes/WidgetBorderRadius.js',
  60. 'classes/WidgetCopy.js',
  61. 'classes/WidgetDelete.js',
  62. 'classes/WidgetEditHTML.js',
  63. 'classes/WidgetIFrame.js',
  64. 'classes/WidgetImgDimensions.js',
  65. 'classes/WidgetImgLink.js',
  66. 'classes/WidgetImgSrc.js',
  67. 'classes/WidgetLayerBottom.js',
  68. 'classes/WidgetLayerTop.js',
  69. 'classes/WidgetLock.js',
  70. 'classes/WidgetOpacity.js',
  71. 'classes/WidgetPadding.js',
  72. 'classes/WidthMarkers.js',
  73. 'classes/Window.js',
  74. 'classes/WindowManager.js'
  75. ];
  76. var cssToInject = [
  77. // Libraries
  78. 'libs/flexicolorpicker/colorpicker.css',
  79. // SuperGlue CSS
  80. 'css/ColorPickerWidget.css',
  81. 'css/CreationMenu.css',
  82. 'css/Document.css',
  83. 'css/DocumentMenu.css',
  84. 'css/FileManagerWindow.css',
  85. 'css/Grid.css',
  86. 'css/HTMLEditor.css',
  87. 'css/Keyboard.css',
  88. 'css/MenuItem.css',
  89. 'css/MenuItemBackgroundColor.css',
  90. 'css/MenuItemBackgroundImg.css',
  91. 'css/MenuItemBackgroundRepeat.css',
  92. 'css/MenuItemCenter.css',
  93. 'css/MenuItemFileManager.css',
  94. 'css/MenuItemNewPage.css',
  95. 'css/MenuItemOutlines.css',
  96. 'css/MenuItemPageTitle.css',
  97. 'css/MenuItemPaste.css',
  98. 'css/MenuItemRedo.css',
  99. 'css/MenuItemSave.css',
  100. 'css/MenuItemSaveAs.css',
  101. 'css/MenuItemSaveLocal.css',
  102. 'css/MenuItemSaveRemote.css',
  103. 'css/MenuItemServerSettings.css',
  104. 'css/MenuItemUndo.css',
  105. 'css/ResizeHandles.css',
  106. 'css/Selection.css',
  107. 'css/SliderWidget.css',
  108. 'css/SuperGlue.css',
  109. 'css/TextEditor.css',
  110. 'css/Widget.css',
  111. 'css/WidgetBackgroundColor.css',
  112. 'css/WidgetBorder.css',
  113. 'css/WidgetBorderColor.css',
  114. 'css/WidgetBorderRadius.css',
  115. 'css/WidgetCopy.css',
  116. 'css/WidgetDelete.css',
  117. 'css/WidgetEditHTML.css',
  118. 'css/WidgetIFrame.css',
  119. 'css/WidgetImgDimensions.css',
  120. 'css/WidgetImgLink.css',
  121. 'css/WidgetImgSrc.css',
  122. 'css/WidgetLayerBottom.css',
  123. 'css/WidgetLayerTop.css',
  124. 'css/WidgetLock.css',
  125. 'css/WidgetOpacity.css',
  126. 'css/WidgetPadding.css',
  127. 'css/WidthMarkers.css',
  128. 'css/Window.css',
  129. 'css/WindowManager.css'
  130. ];
  131. var activateSuperGlue = function(){
  132. var clipboardCss = document.createElement("link");
  133. clipboardCss.setAttribute("data-superglue", "editing-interface");
  134. clipboardCss.setAttribute("rel", "stylesheet");
  135. clipboardCss.setAttribute("href", chrome.extension.getURL("superglue-client//injections/clipboard.css"));
  136. document.head.appendChild(clipboardCss);
  137. var clipboardCopy = document.createElement("textarea");
  138. clipboardCopy.setAttribute("data-superglue", "editing-interface");
  139. clipboardCopy.setAttribute("id", "sg-editing-clipboard-copy");
  140. clipboardCopy.addEventListener('click', function(){
  141. chrome.runtime.sendMessage(
  142. {
  143. action: "copy",
  144. value: clipboardCopy.value
  145. },
  146. function(response){}
  147. );
  148. }, false);
  149. document.body.insertBefore(clipboardCopy, document.body.firstElementChild);
  150. var clipboardPaste = document.createElement("textarea");
  151. clipboardPaste.setAttribute("data-superglue", "editing-interface");
  152. clipboardPaste.setAttribute("id", "sg-editing-clipboard-paste");
  153. clipboardPaste.addEventListener('click', function(){
  154. chrome.runtime.sendMessage(
  155. {
  156. action: "paste",
  157. },
  158. function(response){
  159. if(response.action === 'pasteResponse'){
  160. clipboardPaste.value = response.value;
  161. clipboardPaste.click();
  162. }
  163. }
  164. );
  165. }, false);
  166. document.body.insertBefore(clipboardPaste, document.body.firstElementChild);
  167. for (var i = 0; i < scriptsToInject.length; i++) {
  168. var script = document.createElement("script");
  169. script.setAttribute("data-superglue", "editing-interface");
  170. script.setAttribute("type", "text/javascript");
  171. script.async = false;
  172. script.setAttribute("src", chrome.extension.getURL("superglue-client/" + scriptsToInject[i]) );
  173. document.head.appendChild(script);
  174. };
  175. for (var i = 0; i < cssToInject.length; i++) {
  176. var css = document.createElement("link");
  177. css.setAttribute("data-superglue", "editing-interface");
  178. css.setAttribute("rel", "stylesheet");
  179. css.setAttribute("href", chrome.extension.getURL("superglue-client/" + cssToInject[i]) );
  180. document.head.appendChild(css);
  181. };
  182. var script = document.createElement("script");
  183. script.setAttribute("data-superglue", "editing-interface");
  184. script.setAttribute("type", "text/javascript");
  185. script.async = false;
  186. script.setAttribute("src", chrome.extension.getURL("superglue-client/injections/init.js") );
  187. document.head.appendChild(script);
  188. };
  189. var notSGpage = function(){
  190. var script = document.createElement("script");
  191. script.setAttribute("data-superglue", "editing-interface");
  192. script.setAttribute("type", "text/javascript");
  193. script.async = false;
  194. script.setAttribute("src", chrome.extension.getURL("superglue-client/injections/notSGpage.js") );
  195. document.head.appendChild(script);
  196. document.head.removeChild(script);
  197. };
  198. // check if page is superglue page
  199. if( document.querySelectorAll('meta[name=generator]').length > 0
  200. && document.querySelector('meta[name=generator]').getAttribute('content') === 'SuperGlue'){
  201. // check if editing is active
  202. if( document.querySelectorAll('meta[name=superglue-mode]').length === 0
  203. || document.querySelector('meta[name=superglue-mode]').getAttribute('content') !== 'editing'){
  204. activateSuperGlue();
  205. }
  206. } else { // page is not a superglue page
  207. notSGpage();
  208. }
  209. })();