Explorar el Código

[bug][固定右上角]

zhangwei hace 2 años
padre
commit
31246d4d0b
Se han modificado 2 ficheros con 36 adiciones y 30 borrados
  1. 16 16
      src/logic/content/twitter.js
  2. 20 14
      src/view/content/tool-box/index.vue

+ 16 - 16
src/logic/content/twitter.js

@@ -234,7 +234,7 @@ function _publishTweetEvent(params, cb) {
 
 function onClosePublishDialogHandle(dom, params) {
     // 如果是 Tool box
-    if(params.postType == 3) {
+    if (params.postType == 3) {
         return;
     }
     dom.querySelector('div[role="group"]').addEventListener('click', function () {
@@ -308,7 +308,7 @@ function _addDeNetEditBtn(params = {}) {
                     if (!innerDeIcon) {
                         toolElem.firstChild.appendChild(createTweetToolbarDenet())
                     }
-        
+
                     let innerToolBoxIcon = document.getElementById('de-tool-box-btn-01');
                     if (!innerToolBoxIcon) {
                         toolElem.firstChild.appendChild(createTweetToolbarToolBox())
@@ -739,6 +739,10 @@ export const changeQueueNum = (num = 0) => {
 
 let main_observer = null
 function onChangePageMain(targetNode) {
+    if (main_observer) {
+        return
+    }
+    changeQueueNum(1)
     try {
         const config = { attributes: false, childList: true, subtree: true };
         const callback = (mutationsList, observer) => {
@@ -857,10 +861,7 @@ function initParseCard() {
         if (inTwitter && inTwitterNode) {
             clearInterval(timer)
             setInterval(() => {
-                if (!main_observer) {
-                    onChangePageMain(inTwitterNode)
-                    changeQueueNum(1)
-                }
+                onChangePageMain(inTwitterNode)
                 twitterPinLogin()
                 showNFTGroupIcon()
                 if (queue_num <= 0) {
@@ -878,10 +879,7 @@ function initParseCard() {
         } else if (inFacebook && inFacebookNode) {
             clearInterval(timer)
             setInterval(() => {
-                if (!main_observer) {
-                    onChangePageMain(inFacebookNode)
-                    changeQueueNum(1)
-                }
+                onChangePageMain(inTwitterNode)
                 if (queue_num <= 0) {
                     return
                 }
@@ -2284,7 +2282,7 @@ const fixProfileTabAutoSwitch = () => {
  * 设置Tab Group Iframe 样式
  */
 export const setTabGroupIframeStyle = (params, isReSize = false) => {
-    if(!isReSize) {
+    if (!isReSize) {
         getSysTheme();
     }
     let iframeContent = getGroupTabContentNode();
@@ -2375,11 +2373,13 @@ const getSysTheme = () => {
 const sysThemeChange = () => {
     setTimeout(() => {
         let bgColor = document.querySelector('body').style.backgroundColor;
-        
-        chrome.runtime.sendMessage({ actionType: "CONTENT_SYS_THEME_CHANGE", data: {
-            theme: systemInfo.theme,
-            twitterTheme: bgColor == 'rgb(0, 0, 0)' ? 'dark' : 'light'
-        } }, () => { })
+
+        chrome.runtime.sendMessage({
+            actionType: "CONTENT_SYS_THEME_CHANGE", data: {
+                theme: systemInfo.theme,
+                twitterTheme: bgColor == 'rgb(0, 0, 0)' ? 'dark' : 'light'
+            }
+        }, () => { })
     }, 800)
 }
 

+ 20 - 14
src/view/content/tool-box/index.vue

@@ -69,13 +69,11 @@ let state = reactive({
     postId: '',
     tweetId: '',
     detail: {},
-    dom: {
-        root: null,
-        iframe: null
-    },
     handle_type: ''
 })
 
+let dom = {}
+
 let props = defineProps({
     pre_view: {
         type: Boolean,
@@ -119,9 +117,6 @@ onMounted(() => {
     if (props.pre_view) {
         return
     }
-    // twitterid
-    // postid
-    console.log('dom_toolbox', dom_toolbox.value)
     if (dom_toolbox.value) {
         state.dom_root = dom_toolbox.value.closest('div[data-tweet-id]')
         if (state.dom_root) {
@@ -129,6 +124,17 @@ onMounted(() => {
             state.tweetId = state.dom_root.dataset.tweetId || ''
         }
     }
+    try {
+        dom.fixed = document.querySelector('#denet-tool-box-fixed')
+        if (dom.fixed && dom.fixed.style.display == 'block') {
+            if (dom.fixed.dataset.tweetId == state.tweetId) {
+                state.status = '固定右上角'
+                return
+            }
+        }
+    }catch(error){
+        console.log(error)
+    }
     getDetail()
 })
 
@@ -189,14 +195,14 @@ const handleFull = () => {
     // 切换状态
     state.status = '关闭'
     // 操作全屏dom
-    let dom = document.querySelector('#denet-tool-box-fixed')
-    dom.style.cssText = `
+    dom.fixed.style.cssText = `
         width:100%;
         height: 100%;
         position: fixed;
         right: 0px;
-        top: 0px;`
-    dom.style.display = 'block'
+        top: 0px;
+        display:block;`
+    dom.fixed.dataset.tweetId = state.tweetId
     state.show_btn = false
     sendEventInfo({
         event_type: 'ToolBox_To_Fixed',
@@ -215,14 +221,14 @@ const handleFixed = () => {
     state.show_btn = false
     state.status = '固定右上角'
     // 操作全屏dom
-    let dom = document.querySelector('#denet-tool-box-fixed')
-    dom.style.display = 'block'
-    dom.style.cssText = `
+    dom.fixed.style.cssText = `
+        display:block;
         width: 505px;
         height: 544px;
         position: fixed;
         right: 10px;
         top: 10px;`
+    dom.fixed.dataset.tweetId = state.tweetId
     sendEventInfo({
         event_type: 'ToolBox_To_Fixed',
         data: {