Skip to content

Commit

Permalink
Add a Lights Off switch as fallback
Browse files Browse the repository at this point in the history
Terminal mode does not work well for complicated / scanned PDFs. Use a
(dirty) color-inversion switch to handle them.
  • Loading branch information
shivaprsd committed Dec 17, 2020
1 parent 4056112 commit dd32bc8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ of (non-scanned) PDF files. Read it as if it's on a terminal screen!
2. `cd` into the root directory and run `./install.sh`
3. Follow onscreen instructions

![Screenshot](plugin/images/screenshot.png)

## Notes

Define your colors in `./plugin/colors.json` Default colors are taken from the
Expand All @@ -24,6 +26,10 @@ between Terminal mode and normal view.
text changes only the font-size without touching their position. This may result
in disjoint / overlapping text; **this is not a bug**.

Terminal mode is not suitable for complicated PDFs (LaTeX maths, Indic scripts)
because the text layer will mostly contain rubbish. For them as well as scanned
PDFs use the Lights Off switch (which simply inverts the colors) as a fallback.

## Why *pdfless*?

I love reading on the terminal. The dark background, the colors, the monospaced
Expand Down
Binary file modified plugin/images/logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugin/images/toolbarButton-lightsOff-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugin/images/toolbarButton-lightsOff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion plugin/pdfless.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--termColor: #f7f7f7;
--termBG: #242424;
--termHL: #b0b0b0;
--lightsOff-icon: url(../plugin/images/toolbarButton-lightsOff.svg);
--termMode-icon: url(../plugin/images/toolbarButton-termMode.svg);
--fontInput-icon: url(../plugin/images/secToolbarButton-fontInput.svg);
--colorInput-icon: url(../plugin/images/secToolbarButton-colorInput.svg);
Expand All @@ -14,7 +15,8 @@
}
@media (prefers-color-scheme: dark) {
:root {
--termMode-icon: url(../plugin/images/toolbarButton-termMode-dark.svg);
--lightsOff-icon: url(../plugin/images/toolbarButton-lightsOff-dark.svg);
--termMode-icon: url(../plugin/images/toolbarButton-termMode-dark.svg);
--fontInput-icon: url(../plugin/images/secToolbarButton-fontInput-dark.svg);
--colorInput-icon: url(../plugin/images/secToolbarButton-colorInput-dark.svg);
}
Expand Down Expand Up @@ -72,6 +74,9 @@
content: var(--colorInput-icon);
color: var(--termColor) !important;
}
.toolbarButton.lightsOff::before, .secondaryToolbarButton.lightsOff::before {
content: var(--lightsOff-icon);
}
.toolbarButton.termMode::before, .secondaryToolbarButton.termMode::before {
content: var(--termMode-icon);
}
12 changes: 12 additions & 0 deletions plugin/pdfless.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<template id="toolbarAddon">
<button id="lightsOff" class="toolbarButton lightsOff hiddenLargeView" title="Toggle Lights" tabindex="29">
<span>Lights Off</span>
</button>
<button id="termMode" class="toolbarButton termMode hiddenLargeView" title="Toggle Terminal Mode" tabindex="30">
<span>Terminal Mode</span>
</button>
Expand Down Expand Up @@ -27,11 +30,20 @@
><label for="imageEnable" class="toolbarLabel">Images</label>
</div>
<div class="horizontalToolbarSeparator"></div>
<button id="secLightsOff" class="secondaryToolbarButton lightsOff visibleLargeView" title="Toggle Lights" tabindex="49">
<span>Lights Off</span>
</button>
<button id="secTermMode" class="secondaryToolbarButton termMode visibleLargeView" title="Toggle Terminal Mode" tabindex="50">
<span>Terminal Mode</span>
</button>
</template>

<style id="lightsOffTheme">
.pdfViewer {
filter: invert(86%);
}
</style>

<style id="termModeTheme">
.page {
background-color: var(--termBG) !important;
Expand Down
8 changes: 8 additions & 0 deletions plugin/pdfless.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function pdfLessInit() {
toolbar.prepend(docFrag.getElementById("toolbarAddon").content);
let secToolbar = document.getElementById("secondaryToolbarButtonContainer");
secToolbar.prepend(docFrag.getElementById("secToolbarAddon").content);
document.head.appendChild(docFrag.getElementById("lightsOffTheme"));
document.head.appendChild(docFrag.getElementById("termModeTheme"));
document.head.appendChild(docFrag.getElementById("termModeFont"));
}
Expand All @@ -44,12 +45,14 @@ function getPdfLessConfig() {
textColors: {},
docStyleElem: document.documentElement.style,
colorInputElem: document.getElementById("colorInput"),
lightsOffCSS: document.getElementById("lightsOffTheme"),
termModeCSS: document.getElementById("termModeTheme"),
termModeFontCSS: document.getElementById("termModeFont")
};
}

function pdfLessLoad(config) {
config.lightsOffCSS.disabled = true;
config.termModeCSS.disabled = config.termModeFontCSS.disabled = true;
if (config.termColors.background) {
config.docStyleElem.setProperty("--termBG", config.termColors.background);
Expand Down Expand Up @@ -99,9 +102,14 @@ function pdfLessLoad(config) {
document.getElementById("fontEnlarge").onclick = function(e) {
termFontResize(1 + config.fontScaleFactor);
}
document.getElementById("lightsOff").onclick = toggleLightsOff;
document.getElementById("secLightsOff").onclick = toggleLightsOff;
document.getElementById("termMode").onclick = toggleTermMode;
document.getElementById("secTermMode").onclick = toggleTermMode;

function toggleLightsOff() {
config.lightsOffCSS.disabled = !config.lightsOffCSS.disabled;
}
function toggleTermMode() {
const toTermMode = config.termModeCSS.disabled;
if (toTermMode) {
Expand Down

0 comments on commit dd32bc8

Please sign in to comment.