Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
feat: integrate leanpub styles with extension
Browse files Browse the repository at this point in the history
  • Loading branch information
adil192 committed Mar 14, 2024
1 parent 01d405f commit fd56127
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 243 deletions.
6 changes: 6 additions & 0 deletions build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const styles = <String, List<String>>{
],
// Duo iframe
"shib.manchester.ac.uk_duo": ["*://api-4c039978.duosecurity.com/frame*"],

// Leanpub
"leanpub.com": ["*://leanpub.com/*"],
};

/// Maps each script file to the domains it applies to
Expand All @@ -64,14 +67,17 @@ const scripts = <String, List<String>>{
],
'auto_login': ['*://login.manchester.ac.uk/cas/login*'],
'expand_menu': ['*://online.manchester.ac.uk/webapps/blackboard/content/*'],
'save_scroll_pos': ['*://leanpub.com/*/read*'],
'video_keyboard_shortcuts': ['*://video.manchester.ac.uk/embedded/*'],
};

/// Whether to print extra information.
late final bool verbose;

/// Whether to watch the src directory for changes,
/// and rebuild when changes are detected.
late final bool shouldWatchSrc;

/// Whether to use Manifest V3.
/// If false, Manifest V2 is used.
late final bool useManifestV3;
Expand Down
210 changes: 0 additions & 210 deletions src/leanpub/leanpub_theme.css

This file was deleted.

28 changes: 4 additions & 24 deletions src/leanpub/save_scroll_pos.js → src/scripts/save_scroll_pos.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// ==UserScript==
// @name Where am I? (Leanpub scrolling improvements)
// @namespace http://tampermonkey.net/
// @version 2024-01-24
// @description Saves your scroll position, and highlights the current chapter in the table of contents. Best used with the styles at https://userstyles.world/style/14072/my-personal-leanpub-styles.
// @author adil192
// @match https://leanpub.com/*/read
// @icon https://www.google.com/s2/favicons?sz=64&domain=leanpub.com
// @grant GM_setValue
// @grant GM_getValue
// @grant GM.setValue
// @grant GM.getValue
// ==/UserScript==
// Saves your scroll position,
// and highlights the current chapter in the table of contents.

// @ts-check

Expand All @@ -36,15 +25,6 @@ let tocElem = null;
*/
let pageLoaded = false;

/**
* @typedef {Object} _GM
* @property {(key: string) => Promise<string | undefined>} getValue
* @property {(key: string, value: string) => Promise<void>} setValue
*/
/** @type {_GM} */
// @ts-ignore
const gm = GM;

/**
* Finds the html elements
* @returns {Promise<void>}
Expand Down Expand Up @@ -122,7 +102,7 @@ function onScroll() {
// save current section
if (sectionNumber) {
console.log('Saving last section to', sectionNumber);
gm.setValue('lastSection', sectionNumber);
localStorage.setItem('lastSection', sectionNumber);
}
}
}
Expand All @@ -147,7 +127,7 @@ function onScroll() {
window.addEventListener('load', (e) => {
findElements().then(async () => {
if (!scrollElem || !contentElem || !tocElem) return;
const lastSection = await gm.getValue('lastSection');
const lastSection = localStorage.getItem('lastSection');
console.log('Restoring last section to', lastSection);
if (lastSection) {
const headings = Array.from(contentElem.querySelectorAll('h1, h2, h3, h4, h5, h6'));
Expand Down
19 changes: 10 additions & 9 deletions src/styles/_globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,33 @@ $shadow: rgba($primary, 0.10);
);
}

$font-fallbacks: "Atkinson Hyperlegible", "Inter",
ui-sans-serif, system-ui, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji",
"Segoe UI Symbol", "Noto Color Emoji",
FontAwesome, VideoJS;

@mixin fonts($selector: '*') {
@include hyperlegible;
@include urbanist;

:root {
--fonts-body: #{$font-fallbacks};
--fonts-heading: "Urbanist", "Product Sans", #{$font-fallbacks};
--fonts-body: "Atkinson Hyperlegible", "Inter",
ui-sans-serif, system-ui, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji",
"Segoe UI Symbol", "Noto Color Emoji",
FontAwesome, VideoJS, "Font Awesome 5 Free";
--fonts-heading: "Urbanist", "Product Sans", var(--fonts-body);
}

#{$selector} {
@include fonts-body;
// 'liga' enables font ligatures, 'calt' enables contextual alternates
font-feature-settings: 'liga' 1, 'calt' 1;
font-smooth: always;
-webkit-font-smoothing: subpixel-antialiased;
}
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
.heading, .subheading,
.title, .subtitle,
#pageTitleHeader, #pageTitleText,
.vjs-title-bar-link {
.vjs-title-bar-link,
.book-title {
&, * {
@include fonts-heading;
}
Expand Down
Loading

0 comments on commit fd56127

Please sign in to comment.