Skip to content

Instantly share code, notes, and snippets.

View HeimMatthias's full-sized avatar

HeimMatthias

  • hep Verlag AG
  • Bern, Switzerland
View GitHub Profile
@HeimMatthias
HeimMatthias / World Shakespeare Bibliography Online.js
Created November 21, 2011 16:59
Zotero Translator for the World Shakespeare Bibliography Online
{
"translatorID": "bf6b49e3-9198-4fbc-a559-a81fcfcce908",
"label": "World Shakespeare Bibliography Online",
"creator": "Matthias Heim",
"target": "worldshakesbib.org",
"minVersion": "1.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
@HeimMatthias
HeimMatthias / UnlockEditableRanges.vbs
Created January 27, 2022 09:54
This Excel-VBA script helps you to unlock individual cells that have already been unlocked using the 'editable ranges' method. Since Excel Online and the table versions of Excel do not support the latter method, this script will help you make your partially protected sheets functional on all platforms.
' UnlockEditableRanges: Hebt im aktiven Dokument auf allen Blättern den individuellen Sperrschutz der Zellen auf, die durch bearbeitbare Bereiche freigegeben wurden.
' Dadurch werden diese Bereiche auch auf Excel Online und auf Tablets beschreibbar, selbst wenn das Blatt geschützt ist.
' Achtung: bereits entsperrte Zellen werden durch das Skript nicht wieder geschützt, wenn sie sich nicht (mehr) in einem bearbeitbaren Bereich befinden.
Sub UnlockEditableRanges()
Dim Sheet As Excel.Worksheet
Dim EditableRange As Variant
Dim SheetIsProtected As Boolean
Dim cell As Excel.Range
@HeimMatthias
HeimMatthias / wrapSelectionTextNodes.js
Last active April 3, 2024 16:29
Wraps the currently selected text in span-nodes, with support for Firefox's multiple selection feature, retains selection
/* see implementation example here: jsfiddle.net/s0etmpnf/ */
/* checks whether an (empty) text node is ignored by the browser or rendered */
function isTextNodeUnparsedWhitespace(node) {
if (/[^\t\n\r ]/.test(node.textContent)) return false;
const range = document.createRange();
range.selectNodeContents(node);
const rects = range.getClientRects();
if ((rects.length > 0) && (rects[0].width > 0)) return false;
return true;
@HeimMatthias
HeimMatthias / wrapSelectionInTextNodes.js
Created May 26, 2023 21:48
JavaScript function to wrap selected Text in spans, efficient version without multi-range support
function wrapSelectionTextNodes(id, className) {
let selection = window.getSelection();
let range = selection.getRangeAt(0);
// if the entire range is contained within one text node, there is a quick fix with surroundContents
if (range.startContainer === range.endContainer && range.endContainer.nodeType === Node.TEXT_NODE) {
let span = document.createElement('span');
span.id=id;
span.classList.add(className);
range.surroundContents(span);
selection.selectAllChildren(span);
@HeimMatthias
HeimMatthias / findText.js
Created May 31, 2023 12:04
Find and wrap text in DOM, even across multiple nodes
/*
* will search for a string or a regular expression and wrap resulting textnodes in <span class="selection">-elements
* even if the result spans multiple text nodes.
* returns the new span-nodes as a two-dimensional array, where each entry corresponds to all the wrapped text nodes for a result of the search, loop over these to add ids
* (as an added goodie, the returned element contains the 'text' of each result, as well as 'context.before' and 'context.after', a trimmed 100-character string of the surrounding content)
*/
function findText(root, regex) {
if (regex instanceof RegExp) {
if (!regex.flags.includes("g")) regex = new RegExp(regex.source,"g"+regex.flags);
} else {
@HeimMatthias
HeimMatthias / document-outline-extension.js
Created May 27, 2024 22:07
MuPDF OutlineIterator Extension to get outline item color and style (italic/bold) information
/*
* Use MuPDF's JavaScript API to get "table of contents" / document outline styling information
* Set up an OutlineIterator (as in the main function below) but additionally allows you to retrieve the pdf object for each entry and to get and set style and color
* (Also: full example of an outline parser in MuPDF in main function below)
* v.1 - 27.05.2024
* run as follows: mutool.exe run document-outline-extension.js filename.pdf
*
* Copyright (C) 2024 Matthias Heim
This program is free software: you can redistribute it and/or modify
/*
* Use MuPDF's JavaScript API to copy the "table of contents" / document outline from one pdf file to another
* The script also copies styling information (italics / bold / color), by accessing this information via
* mupdf's PDFObject-API. It is mainly intended as a proof of concept for this type of operation.
* This is useful if you have to versions of the same pdf and want to copy the outline from one version to another
* Warning: the script performs no checks whether the outlined targets exist or make sense in the new document.
* Warning: this script removes existing outlines from the target document and overwrites it in place.
* Always keep a copy of the target document in case something goes horribly wrong.
* v.1 - 13.03.2025
* run as follows: node copytoc.mjs source.pdf target.pdf