From a95d41fa5c2e7745ec24d669b41e3444dc23675b Mon Sep 17 00:00:00 2001 From: Enix Date: Thu, 11 Apr 2019 10:05:23 +0800 Subject: [PATCH] refactor: handle plain readme --- src/utils/DOMHelper.ts | 63 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/utils/DOMHelper.ts b/src/utils/DOMHelper.ts index b43b0e8..71126ae 100644 --- a/src/utils/DOMHelper.ts +++ b/src/utils/DOMHelper.ts @@ -319,37 +319,40 @@ const clippy = createClippy() let currentCodeSnippetElement: Element function attachCopySnippet() { - const readmeArticleSelector = '.repository-content #readme article' - return $( - readmeArticleSelector, - readmeElement => - readmeElement.addEventListener('mouseover', e => { - // only move clippy when mouse is over a new snippet(
)
-        const target = e.target as Element
-        if (target.nodeName === 'PRE') {
-          if (currentCodeSnippetElement !== target) {
-            currentCodeSnippetElement = target
-            /**
-             *  
- *
     
-             *    
- *
   
-             *    
- *
- */ - if (target.parentNode) target.parentNode.insertBefore(clippy, target) + const readmeSelector = '.repository-content #readme' + return $(readmeSelector, () => { + const readmeArticleSelector = '.repository-content #readme article' + $( + readmeArticleSelector, + readmeElement => + readmeElement.addEventListener('mouseover', e => { + // only move clippy when mouse is over a new snippet(
)
+          const target = e.target as Element
+          if (target.nodeName === 'PRE') {
+            if (currentCodeSnippetElement !== target) {
+              currentCodeSnippetElement = target
+              /**
+               *  
+ *
     
+               *    
+ *
   
+               *    
+ *
+ */ + if (target.parentNode) target.parentNode.insertBefore(clippy, target) + } } - } - }), - () => { - const readmeSelector = '.repository-content #readme' - $(readmeSelector, () => - raiseError( - new Error('cannot find mount point for copy snippet button while readme exists'), - ), - ) - }, - ) + }), + () => { + const plainReadmeSelector = '.repository-content #readme .plain' + $(plainReadmeSelector, undefined, () => + raiseError( + new Error('cannot find mount point for copy snippet button while readme exists'), + ), + ) + }, + ) + }) } /**