mirror of
				https://github.com/notion-enhancer/notion-enhancer.git
				synced 2025-11-05 00:28:07 +11:00 
			
		
		
		
	feat: update no-peeking extension (formerly bypass-preview)
This commit is contained in:
		
							parent
							
								
									5b22ca9ff9
								
							
						
					
					
						commit
						73665e9743
					
				@ -1,35 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * notion-enhancer: bypass preview
 | 
					 | 
				
			||||||
 * (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
 | 
					 | 
				
			||||||
 * (https://notion-enhancer.github.io/) under the MIT license
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default function ({ web, notion }, db) {
 | 
					 | 
				
			||||||
  let _openPage = {};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const getCurrentPage = () => ({
 | 
					 | 
				
			||||||
    type: web.queryParams().get("p") ? "preview" : "page",
 | 
					 | 
				
			||||||
    id: notion.getPageID(),
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const interceptPreview = () => {
 | 
					 | 
				
			||||||
    const currentPage = getCurrentPage();
 | 
					 | 
				
			||||||
    if (
 | 
					 | 
				
			||||||
      currentPage.id !== _openPage.id ||
 | 
					 | 
				
			||||||
      currentPage.type !== _openPage.type
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      const $openAsPage = document.querySelector(
 | 
					 | 
				
			||||||
        ".notion-peek-renderer a > div"
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if ($openAsPage) {
 | 
					 | 
				
			||||||
        if (currentPage.id === _openPage.id && currentPage.type === "preview") {
 | 
					 | 
				
			||||||
          history.back();
 | 
					 | 
				
			||||||
        } else $openAsPage.click();
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      _openPage = getCurrentPage();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
  web.addDocumentObserver(interceptPreview, [".notion-peek-renderer"]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,22 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
  "name": "bypass preview",
 | 
					 | 
				
			||||||
  "id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f",
 | 
					 | 
				
			||||||
  "version": "0.2.0",
 | 
					 | 
				
			||||||
  "description": "go straight to the normal full view when opening a page.",
 | 
					 | 
				
			||||||
  "tags": ["extension", "automation"],
 | 
					 | 
				
			||||||
  "authors": [
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      "name": "dragonwocky",
 | 
					 | 
				
			||||||
      "email": "thedragonring.bod@gmail.com",
 | 
					 | 
				
			||||||
      "homepage": "https://dragonwocky.me/",
 | 
					 | 
				
			||||||
      "avatar": "https://dragonwocky.me/avatar.jpg"
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
  "js": {
 | 
					 | 
				
			||||||
    "client": ["client.mjs"]
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "css": {
 | 
					 | 
				
			||||||
    "client": ["client.css"]
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "options": []
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * notion-enhancer: bypass preview
 | 
					 * notion-enhancer: no-peeking
 | 
				
			||||||
 * (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
 | 
					 * (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
 | 
				
			||||||
 * (https://notion-enhancer.github.io/) under the MIT license
 | 
					 * (https://notion-enhancer.github.io/) under the MIT license
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
							
								
								
									
										26
									
								
								src/extensions/no-peeking/client.mjs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/extensions/no-peeking/client.mjs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * notion-enhancer: no peeking
 | 
				
			||||||
 | 
					 * (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
 | 
				
			||||||
 | 
					 * (https://notion-enhancer.github.io/) under the MIT license
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default async (api) => {
 | 
				
			||||||
 | 
					  const { addMutationListener } = api,
 | 
				
			||||||
 | 
					    peekRenderer = ".notion-peek-renderer",
 | 
				
			||||||
 | 
					    openInFullPage = `[aria-label="Open in full page"]`,
 | 
				
			||||||
 | 
					    pageId = () => location.pathname.split(/-|\//g).at(-1),
 | 
				
			||||||
 | 
					    peekId = () => new URLSearchParams(location.search).get("p");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let _pageId = pageId();
 | 
				
			||||||
 | 
					  const skipPeek = () => {
 | 
				
			||||||
 | 
					    const $openInFullPage = document.querySelector(openInFullPage);
 | 
				
			||||||
 | 
					    if (peekId() === _pageId) {
 | 
				
			||||||
 | 
					      _pageId = pageId();
 | 
				
			||||||
 | 
					      history.back();
 | 
				
			||||||
 | 
					    } else if (peekId() && $openInFullPage) {
 | 
				
			||||||
 | 
					      _pageId = peekId();
 | 
				
			||||||
 | 
					      $openInFullPage.click();
 | 
				
			||||||
 | 
					    } else _pageId = pageId();
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  addMutationListener(peekRenderer, skipPeek);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/extensions/no-peeking/mod.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/extensions/no-peeking/mod.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "No Peeking",
 | 
				
			||||||
 | 
					  "id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f",
 | 
				
			||||||
 | 
					  "version": "0.3.0",
 | 
				
			||||||
 | 
					  "description": "Globally force pages opening in side peek or center peek to open as full pages instead.",
 | 
				
			||||||
 | 
					  "tags": ["automation"],
 | 
				
			||||||
 | 
					  "authors": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "dragonwocky",
 | 
				
			||||||
 | 
					      "homepage": "https://dragonwocky.me/",
 | 
				
			||||||
 | 
					      "avatar": "https://dragonwocky.me/avatar.jpg"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "clientStyles": ["client.css"],
 | 
				
			||||||
 | 
					  "clientScripts": ["client.mjs"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,5 +5,6 @@
 | 
				
			|||||||
  "extensions/scroller",
 | 
					  "extensions/scroller",
 | 
				
			||||||
  "extensions/outliner",
 | 
					  "extensions/outliner",
 | 
				
			||||||
  "extensions/word-counter",
 | 
					  "extensions/word-counter",
 | 
				
			||||||
 | 
					  "extensions/no-peeking",
 | 
				
			||||||
  "themes/classic-dark"
 | 
					  "themes/classic-dark"
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user