Last active
August 29, 2015 14:07
-
-
Save markbao/7f8662225f92a3480600 to your computer and use it in GitHub Desktop.
Quip Autofocus — Quip's focus mode, accessible by the "Hide Conversation" button, is awesome. But since the majority of the documents I use Quip for are personal documents, I've found it a pain to always have to click it. This incredibly hacky userscript automatically enables focus mode when opening a Quip document. You can go back to the docume…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quip Autofocus | |
// Super hacky, not optimal, but "damn it, it works" | |
// I'll come up with a better solution after exams | |
// suggested namespace: *quip.com* | |
// I use this in a Fluid app as a Userscript. Not tested anywhere else | |
console.log('quip.autofocus.js - Loading Quip autofocus'); | |
var qafFocusedThread = null; // stores the last focused thread ID | |
// allows js to only focus once, | |
// allowing user to show conversation pane | |
// simple toggle/bool isn't used, since we might need to focus | |
// if the user navigates via link to another Quip document | |
setInterval(function() { | |
// Check if a thread (document) is active | |
if (document.querySelector('.thread') != null) { | |
// Thread is active | |
// Check if focused | |
if (document.querySelector('.thread.focused') == null) { | |
// Thread is not focused | |
// Get the thread ID | |
var qafThreadId = window.location.href.replace('https://quip.com/','') | |
// Have we already autofocused this thread? | |
// a.k.a., is the last doc we autofocused the current one? | |
if (qafThreadId == qafFocusedThread) { | |
// Thread previously focused, so don't focus | |
// This allows the user to still show the conversation pane to go back | |
} else { | |
// Not yet focused, focus | |
console.log('quip.autofocus.js - Focusing'); | |
// Prepare to go zen | |
document.querySelector('.focus-mode-on').click() | |
// Save current focusedDoc (thread) | |
qafFocusedThread = qafThreadId; | |
} | |
} | |
} else { | |
// Thread not active - don't focus | |
// but clear focusedDoc, since the user might have gone back | |
// this allows user to go to doc A, go back, | |
// then go to doc A again, autofocused | |
if (qafFocusedThread != null) { | |
qafFocusedThread = null; | |
} | |
} | |
}, 500); // told you it was hacky. need to see if there is a hook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment