Skip to content

Commit

Permalink
added feature Open full page instead of preview
Browse files Browse the repository at this point in the history
  • Loading branch information
GorvGoyl committed Jun 16, 2021
1 parent e2c22d9 commit 69bbfec
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"plugin:react-hooks/recommended"
],
"rules": {
"prefer-destructuring": "off",
"comma-spacing": "off",
"no-multiple-empty-lines": "off",
"indent": "off",
"no-lonely-if": "off",
"no-loop-func": "off",
"space-before-blocks": "off",
Expand Down
3 changes: 3 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- notion-scroller vertical horizontal _resets on doc change_
- `notion-page-content`
- blocks
- notion-overlay-container notion-default-overlay-container
- notion-peek-renderer
- notion-overlay-container

# Run in FF

Expand Down
14 changes: 10 additions & 4 deletions src/js/content.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import "../css/content.scss";
import { defaultSettings } from "./settings";
import { isEmpty, getLatestSettings } from "./utility";
import { codeLineNumbers } from "./feature/codeLineNumbers";
import { openFullPage } from "./feature/openFullPage";
import { displayOutline } from "./feature/outline";
import * as features from "./feature/pageElements";
import { scrollTopBtn } from "./feature/scrollToTopBtn";
import { codeLineNumbers } from "./feature/codeLineNumbers";
// step 1 of 2: import feature
import { spellcheckForCode } from "./feature/spellcheckForCode.js";
import * as features from "./feature/pageElements";
import { defaultSettings } from "./settings";
import { getLatestSettings, isEmpty } from "./utility";

let featureList = {};

featureList = features;

// step 2 of 2: add that feature to featureList object
featureList.displayOutline = displayOutline;
featureList.scrollTopBtn = scrollTopBtn;
featureList.codeLineNumbers = codeLineNumbers;
featureList.spellcheckForCode = spellcheckForCode;
featureList.openFullPage = openFullPage;

function init() {
let syncSet = {};
const updatedSet = { ...defaultSettings };
Expand Down
125 changes: 125 additions & 0 deletions src/js/feature/openFullPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { getElement, isObserverType, onElementLoaded } from "../utility";

const notionDefaultOverlayCls = ".notion-default-overlay-container";

const DEBUG = true;

let docEditObserverObj = {};

export function openFullPage(isEnabled) {
try {
console.log(`feature: enableOpenFullPage: ${isEnabled}`);

// triggers on page load
// it waits for overlay to be loaded
onElementLoaded(notionDefaultOverlayCls)
.then((isPresent) => {
if (isPresent) {
if (isEnabled) {
addOpenFullPage();
} else {
removeOpenFullPage();
}
}
return true;
})
.catch((e) => console.log(e));
} catch (e) {
console.log(e);
}
}

// Internal methods //

function removeDocEditListener() {
if (isObserverType(docEditObserverObj)) {
DEBUG && console.log("disconnected docEditObserver");
docEditObserverObj.disconnect();
}
}
let lastPageID;

/*
Algo:
case 1: open page and bypass preview
id -> id?p -> p
here lastPageID is id
case 2: navigate back and bypass preview
id <- id?p <- p
here lastPageID is p
*/
function docEditListener() {
console.log("listening for doc edit changes for openFullPage...");

docEditObserverObj = new MutationObserver((mutationList, obsrvr) => {
DEBUG && console.log("found changes in doc content");
const curUrl = window.location.href;

// save last page url
if (!curUrl.includes("&p=") && !curUrl.includes("?p=")) {
// All credits goes to 'dragonwocky' for this approach
lastPageID = (window.location.search
.slice(1)
.split("&")
.map((opt) => opt.split("="))
.find((opt) => opt[0] === "p") || [
"",
...window.location.pathname.split(/(-|\/)/g).reverse(),
])[1];
}
for (let i = 0; i < mutationList.length; i++) {
const m = mutationList[i];

// case: check for div change
if (m.type === "childList" && m.addedNodes.length > 0 && m.target) {
const fullPageLink = m.target.querySelector(
".notion-peek-renderer [style*='height: 45px;'] > a"
);

if (!fullPageLink) return;

const previewPageID = (fullPageLink.href
.slice(1)
.split("&")
.map((opt) => opt.split("="))
.find((opt) => opt[0] === "p") || [
"",
...fullPageLink.pathname.split(/(-|\/)/g).reverse(),
])[1];

if (previewPageID) {
if (previewPageID === lastPageID) {
console.log("going back", lastPageID);
window.history.back();
} else {
console.log("full page link found", fullPageLink.href);
fullPageLink.click();
}
}
}
}
});

// now add listener for doc text change
const defaultOverlayEl = getElement(notionDefaultOverlayCls);

docEditObserverObj.observe(defaultOverlayEl, {
childList: true,
subtree: true,
});
}
function addOpenFullPage() {
docEditListener();
}

function removeOpenFullPage() {
console.log("removing removeOpenFullPage feature...");

removeDocEditListener();

console.log("openFullPage feature removed");
}
22 changes: 14 additions & 8 deletions src/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export const defaultSettings = {
addMoreHeightToPage: false,
spellcheckForCode: false,
codeLineNumbers: false,
// step 1 of 2: add function name
openFullPage: false,
};

export const settingDetails = [
{
func: "displayOutline",
name: "Show Outline",
desc:
"Show sticky outline (table of contents) for pages that have headings",
desc: "Show sticky outline (table of contents) for pages that have headings",
pf: false,
},
{
Expand All @@ -40,6 +41,12 @@ export const settingDetails = [
desc: "Set small text for all pages by default",
pf: false,
},
{
func: "openFullPage",
name: "Open full page instead of preview",
desc: "Bypass preview and open full page of table, board, etc",
pf: false,
},
{
func: "scrollTopBtn",
name: "'Scroll to top' button",
Expand Down Expand Up @@ -75,15 +82,13 @@ export const settingDetails = [
{
func: "spellcheckForCode",
name: "Enable spellcheck inside code blocks",
desc:
"Show squiggly red lines for any spelling mistakes inside code blocks",
desc: "Show squiggly red lines for any spelling mistakes inside code blocks",
pf: false,
},
{
func: "disablePopupOnURLPaste",
name: "Don't show popup menu when pasting external links",
desc:
"Don't show popup menu i.e (dismiss, create bookmark, create embed) when pasting external links",
desc: "Don't show popup menu i.e (dismiss, create bookmark, create embed) when pasting external links",
pf: false,
},
{
Expand All @@ -102,8 +107,7 @@ export const settingDetails = [
{
func: "hideNotification",
name: "Hide notification icon",
desc:
"Hide red notification icon from sidebar when it's in closed state and hide notification number from tab title",
desc: "Hide red notification icon from sidebar when it's in closed state and hide notification number from tab title",
pf: true,
},
{
Expand Down Expand Up @@ -137,4 +141,6 @@ export const settingDetails = [
desc: "",
pf: false,
},

// step 2 of 2: add function name and description
];
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Notion Boost",
"short_name": "Notion Boost",
"version": "2.0.1",
"version": "2.2",
"description": "Boost Notion productivity with 15+ customizations like outline,small text full width for all,back to top button etc",
"author": "Gourav Goyal",

Expand Down

0 comments on commit 69bbfec

Please sign in to comment.