Skip to content

Commit

Permalink
See releasenotes for 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fjwillemsen committed Mar 2, 2023
1 parent d5018e3 commit fdc092b
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 22 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Scripts/appversion.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const appversion = "1.7.6";
const appversion = "1.8.0";
10 changes: 6 additions & 4 deletions Scripts/colormode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const overallThemeToOverleaf = {
};

function switchColorModePDF() {
if (current_colorscheme_preference == "dark") {
$(".pdf-viewer .pdfjs-viewer .page").addClass("conditional-invert-colors");
} else if (current_colorscheme_preference == "light") {
$(".pdf-viewer .pdfjs-viewer .page").removeClass("conditional-invert-colors");
if (up_colormode_switching_pdf == true) {
if (current_colorscheme_preference == "dark") {
$(".pdf-viewer .pdfjs-viewer .page").addClass("conditional-invert-colors");
} else if (current_colorscheme_preference == "light") {
$(".pdf-viewer .pdfjs-viewer .page").removeClass("conditional-invert-colors");
}
}
}

Expand Down
28 changes: 20 additions & 8 deletions Scripts/css.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// This file is not intended to run by itself, but is inserted into main.js

// inserting CSS
function addCSS() {
const css_text = `
/**
* Function to insert CSS
*/
function setCSS() {
var css_text = `
body {
background-color: #fff;
color: black;
}
.loading-screen {
background-color: #fff;
#left-menu {
color: black;
}
.native-overleaf-settings {
display: inline-block;
width: 260px;
.loading-screen {
background-color: #fff;
}
.settings-toggle {
Expand Down Expand Up @@ -228,6 +229,17 @@ function addCSS() {
}
}
`;
// add the editor font family if specified
let editor_font_family = up_editor_font_family;
if (up_editor_font_family.length <= 0) {
editor_font_family = "inherit";
}
css_text += `
.cm-editor {
--source-font-family: ${editor_font_family} !important;
}`;

// set the CSS
let styleSheet = document.createElement("style");
styleSheet.innerText = css_text;
document.head.appendChild(styleSheet);
Expand Down
70 changes: 70 additions & 0 deletions Scripts/extension_writefull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const extensionId = "opgfklgemimfakkhhenkjpebopabfjjd";

// Release
const writefullUrl = "https://storage.googleapis.com/writefull-cdn/writefull.js";

let isRunning = false;
document.addEventListener("readystatechange", (event) => {
isRunning = true;
console.log("Writefull");

if (
document.readyState === "interactive" ||
(document.readyState === "complete" && !window._writefull && !isRunning)
) {
console.log("Writefull readystatechange");
const scriptCM6 = document.createElement("script");
scriptCM6.type = "text/javascript";
scriptCM6.innerHTML = `
window.addEventListener('UNSTABLE_editor:extensions', (event) => {
if (event.detail) {
const { CodeMirror, extensions } = event.detail;
window._writefull = {
...CodeMirror,
extensions
}
}
if (window.w$) {
w$.reloadEditor();
}
});
window.addEventListener('editor:extensions', (event) => {
if (event.detail) {
const { CodeMirror, extensions } = event.detail;
window._writefull = {
...CodeMirror,
extensions
}
}
if (window.w$) {
w$.reloadEditor();
}
});
`;
document.body.append(scriptCM6);
setTimeout(() => {
scriptCM6.remove();
}, 0);
isRunning = false;
}
});

const load = function () {
setTimeout(function () {
const script = document.createElement("script");
script.src = `${writefullUrl}?ts=${+new Date()}`;
console.log(script.src);
script.type = "text/javascript";
document.body.append(script);
console.log("Writefull appended!");
console.log(document.body);
setTimeout(() => {
script.remove();
}, 0);
}, 1000);
};
window.addEventListener("load", load);
3 changes: 2 additions & 1 deletion Scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ if (window.matchMedia) {
<<insert="wordcount.js">>
<<insert="backup.js">>
<<insert="chart.js">>
// <<insert="extension_writefull.js">>

// start
const startTime = performance.now();
setupColormode()
setupNotifications()
setupPreferencesPane()
addCSS()
setCSS()
setAutoUpdateChecking()
setupWordCount()
showChangelogIfUpdated()
Expand Down
19 changes: 19 additions & 0 deletions Scripts/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let up_editortheme_light = localStorage.getObject("editortheme_light", editorThe
let up_wordcount_tracking = localStorage.getObject("wordcount_tracking", true); // whether wordcount tracking is enabled
let up_wordcount_dailytarget = localStorage.getObject("wordcount_dailytarget", 200); // net number of words that must be produced daily
let up_wordcount_notificationhour = localStorage.getObject("wordcount_notificationhour", 18); // hour of the day at which the user is notified whether they have achieved their goal
let up_editor_font_family = localStorage.getObject("editor_font_family", "");

// user preferences boundaries
let up_wordcount_dailytarget_min = 1;
Expand Down Expand Up @@ -111,6 +112,10 @@ function setupPreferencesPane() {
<span class="settings-toggle-label">Resolved suggestions</span>
</label>
<hr/>
<h6>Customizations</h6>
<label>Editor font family <br/><i>(leave empty for default)</i></label>
<input id="editor_font_family" type="text"/>
<hr/>
<h6>Dark / Light Mode</h6>
<label class="settings-toggle">
<input id="colormode_switching" class="settings-toggle-checkbox" type="checkbox">
Expand Down Expand Up @@ -199,6 +204,7 @@ function setupPreferencesPane() {
settings_form.querySelector("#wordcount_tracking").checked = up_wordcount_tracking;
settings_form.querySelector("#wordcount_dailytarget").value = up_wordcount_dailytarget;
settings_form.querySelector("#wordcount_notificationhour").value = up_wordcount_notificationhour;
settings_form.querySelector("#editor_font_family").value = up_editor_font_family;

// set the disabled values where necessary
settings_form.querySelector("#colormode_switching_pdf").disabled = !up_colormode_switching;
Expand Down Expand Up @@ -254,6 +260,7 @@ const settings_handler = {
wordcount_tracking: set_wordcount_tracking,
wordcount_dailytarget: set_wordcount_dailytarget,
wordcount_notificationhour: set_wordcount_notificationhour,
editor_font_family: set_editor_font_family,
};

function set_notifications_tracked_changes_created(key, value) {
Expand Down Expand Up @@ -384,6 +391,18 @@ function set_notifications_comment_response(key, value) {
}
}

//
// Customization
//

function set_editor_font_family(key, value) {
if (value.value != up_editor_font_family) {
up_editor_font_family = value.value;
localStorage.setObject(key, value.value);
setCSS();
}
}

//
// Themes
//
Expand Down
1 change: 1 addition & 0 deletions Scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function checkForUpdate(reportAll = false) {
// first check if we have not already notified the user of this latest version
const previous_version_checked = localStorage.getObject("previous_version_checked");
if (
reportAll == false &&
previous_version_checked !== undefined &&
semanticVersionCompare(latest_version, previous_version_checked) == 0
) {
Expand Down
37 changes: 32 additions & 5 deletions Scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ Storage.prototype.getObject = function (key, defaultvalue = undefined) {
return defaultvalue;
};

// function that returns the current local date of the user as a "YYYY-MM-DD" formatted string
/**
* Function that returns the current local date of the user as a "YYYY-MM-DD" formatted string
*/
function getLocalDate() {
return new Date().toLocaleDateString("en-CA");
}

// function to retrieve the ShowdownJS library for converting Markdown to HTML
/**
* Function to get the time in seconds since epoch
*/
function getTimeInSeconds() {
return Math.round(new Date().getTime() / 1000);
}

/**
* Function to retrieve the ShowdownJS library for converting Markdown to HTML
*/
async function insertShowdownJS() {
$.ajaxSetup({ cache: true });
return $.when($.getScript("https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"))
Expand All @@ -29,7 +40,13 @@ async function insertShowdownJS() {
});
}

// function that injects dialog HTML code in the proper location, adds close button and close-when-clicked-outside and returns reference to the element
/**
* Function that injects dialog HTML code in the proper location, adds close button and close-when-clicked-outside and returns reference to the element
* @param {Number} id
* @param {string} innerhtml
* @param {string} insertionselector
* @returns
*/
function injectDialog(id, innerhtml, insertionselector = "body") {
const html = `<dialog id=${id}>
<span id="closebutton" class="close">&times;</span>
Expand All @@ -56,7 +73,15 @@ function injectDialog(id, innerhtml, insertionselector = "body") {
return dialog;
}

// function that checks a function returning a boolean and backs off for waitTime duration if it is not yet true, maximum numberOfTimesToCheck times
/**
* Function that checks a function returning a boolean and backs off for waitTime seconds. If it is not yet true, maximum numberOfTimesToCheck times.
* @param {Function} checkFunction
* @param {Number} waitTime
* @param {Number} numberOfTimesToCheck
* @param {Number} multiplyWaitTime
* @param {Number} numberOfTimesChecked
* @returns
*/
function recursiveCheckAndWait(
checkFunction,
waitTime,
Expand Down Expand Up @@ -94,7 +119,9 @@ function recursiveCheckAndWait(
}
}

// function for mapping the difference between two objects
/**
* Function for mapping the difference between two objects
*/
const deepDiffMapper = (function () {
return {
VALUE_CREATED: "created",
Expand Down
11 changes: 9 additions & 2 deletions Scripts/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function setHasBeenNotified(value) {
}

// setup the repeated execution of updateWordCount
var last_compile_wordcount_time = -60;
async function setupWordCount() {
if (up_wordcount_tracking == true) {
if (this.project_id === undefined) {
Expand All @@ -143,13 +144,19 @@ async function setupWordCount() {
if ((await waitUntilPDFCompiled()) != false) {
// set the initial word count on load
updateWordCount();
last_compile_wordcount_time = getTimeInSeconds();

// set the observer for when the PDF is recompiled
let pdf_element = getBackupElement(1);
if (compilation_observer === undefined) {
compilation_observer = new MutationObserver(function (mutations) {
console.log("PDF compiled, updating wordcount");
updateWordCount();
if (current_time - last_compile_wordcount_time < 60) {
console.log("PDF compiled, but wordcount already recalculated in the last 60 seconds");
} else {
console.log("PDF compiled, updating wordcount");
updateWordCount();
last_compile_wordcount_time = getTimeInSeconds();
}
});
}
compilation_observer.observe(pdf_element, {
Expand Down
2 changes: 1 addition & 1 deletion bundled_script.js

Large diffs are not rendered by default.

0 comments on commit fdc092b

Please sign in to comment.