Wikipedia:Reference desk/Computing
of the Wikipedia reference desk.
Main page: Help searching Wikipedia
How can I get my question answered?
- Select the section of the desk that best fits the general topic of your question (see the navigation column to the right).
- Post your question to only one section, providing a short header that gives the topic of your question.
- Type '~~~~' (that is, four tilde characters) at the end – this signs and dates your contribution so we know who wrote what and when.
- Don't post personal contact information – it will be removed. Any answers will be provided here.
- Please be as specific as possible, and include all relevant context – the usefulness of answers may depend on the context.
- Note:
- We don't answer (and may remove) questions that require medical diagnosis or legal advice.
- We don't answer requests for opinions, predictions or debate.
- We don't do your homework for you, though we'll help you past the stuck point.
- We don't conduct original research or provide a free source of ideas, but we'll help you find information you need.
How do I answer a question?
Main page: Wikipedia:Reference desk/Guidelines
- The best answers address the question directly, and back up facts with wikilinks and links to sources. Do not edit others' comments and do not give any medical or legal advice.
August 17
Need help interpreting JavaScript code
I am currently learning HTML and I was viewing the source code of my website that I had pre-built using a web hosting service. Included in the source code was the following JavaScript:
(function () { var on = addEventListener, $ = function (q) { return document.querySelector(q) }, $$ = function (q) { return document.querySelectorAll(q) }, $body = document.body, $inner = $('.inner'), client = (function () { var o = { browser: 'other', browserVersion: 0, os: 'other', osVersion: 0, mobile: false, canUse: null, flags: { lsdUnits: false, }, }, ua = navigator.userAgent, a, i; a = [['firefox', /Firefox\/([0-9\.]+)/], ['edge', /Edge\/([0-9\.]+)/], ['safari', /Version\/([0-9\.]+).+Safari/], ['chrome', /Chrome\/([0-9\.]+)/], ['chrome', /CriOS\/([0-9\.]+)/], ['ie', /Trident\/.+rv:([0-9]+)/]]; for (i = 0; i < a.length; i++) { if (ua.match(a[i][1])) { o.browser = a[i][0]; o.browserVersion = parseFloat(RegExp.$1); break; } } a = [['ios', /([0-9_]+) like Mac OS X/, function (v) { return v.replace('_', '.').replace('_', ''); }], ['ios', /CPU like Mac OS X/, function (v) { return 0 }], ['ios', /iPad; CPU/, function (v) { return 0 }], ['android', /Android ([0-9\.]+)/, null], ['mac', /Macintosh.+Mac OS X ([0-9_]+)/, function (v) { return v.replace('_', '.').replace('_', ''); }], ['windows', /Windows NT ([0-9\.]+)/, null], ['undefined', /Undefined/, null],]; for (i = 0; i < a.length; i++) { if (ua.match(a[i][1])) { o.os = a[i][0]; o.osVersion = parseFloat(a[i][2] ? (a[i][2])(RegExp.$1) : RegExp.$1); break; } } if (o.os == 'mac' && ('ontouchstart' in window) && ((screen.width == 1024 && screen.height == 1366) || (screen.width == 834 && screen.height == 1112) || (screen.width == 810 && screen.height == 1080) || (screen.width == 768 && screen.height == 1024))) o.os = 'ios'; o.mobile = (o.os == 'android' || o.os == 'ios'); var _canUse = document.createElement('div'); o.canUse = function (property, value) { var style; style = _canUse.style; if (!(property in style)) return false; if (typeof value !== 'undefined') { style[property] = value; if (style[property] == '') return false; } return true; }; o.flags.lsdUnits = o.canUse('width', '100dvw'); return o; }()), trigger = function (t) { dispatchEvent(new Event(t)); }, cssRules = function (selectorText) { var ss = document.styleSheets, a = [], f = function (s) { var r = s.cssRules, i; for (i = 0; i < r.length; i++) { if (r[i] instanceof CSSMediaRule && matchMedia(r[i].conditionText).matches) (f)(r[i]); else if (r[i] instanceof CSSStyleRule && r[i].selectorText == selectorText) a.push(r[i]); } }, x, i; for (i = 0; i < ss.length; i++)f(ss[i]); return a; }, thisHash = function () { var h = location.hash ? location.hash.substring(1) : null, a; if (!h) return null; if (h.match(/\?/)) { a = h.split('?'); h = a[0]; history.replaceState(undefined, undefined, '#' + h); window.location.search = a[1]; } if (h.length > 0 && !h.match(/^[a-zA-Z]/)) h = 'x' + h; if (typeof h == 'string') h = h.toLowerCase(); return h; }, scrollToElement = function (e, style, duration) { var y, cy, dy, start, easing, offset, f; if (!e) y = 0; else { offset = (e.dataset.scrollOffset ? parseInt(e.dataset.scrollOffset) : 0) * parseFloat(getComputedStyle(document.documentElement).fontSize); switch (e.dataset.scrollBehavior ? e.dataset.scrollBehavior : 'default') { case 'default': default: y = e.offsetTop + offset; break; case 'center': if (e.offsetHeight < window.innerHeight) y = e.offsetTop - ((window.innerHeight - e.offsetHeight) / 2) + offset; else y = e.offsetTop - offset; break; case 'previous': if (e.previousElementSibling) y = e.previousElementSibling.offsetTop + e.previousElementSibling.offsetHeight + offset; else y = e.offsetTop + offset; break; } } if (!style) style = 'smooth'; if (!duration) duration = 750; if (style == 'instant') { window.scrollTo(0, y); return; } start = Date.now(); cy = window.scrollY; dy = y - cy; switch (style) { case 'linear': easing = function (t) { return t }; break; case 'smooth': easing = function (t) { return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1 }; break; }f = function () { var t = Date.now() - start; if (t >= duration) window.scroll(0, y); else { window.scroll(0, cy + (dy * easing(t / duration))); requestAnimationFrame(f); } }; f(); }, scrollToTop = function () { scrollToElement(null); }, loadElements = function (parent) { var a, e, x, i; a = parent.querySelectorAll('iframe[data-src]:not([data-src=""])'); for (i = 0; i < a.length; i++) { a[i].src = a[i].dataset.src; a[i].dataset.src = ""; } a = parent.querySelectorAll('video[autoplay]'); for (i = 0; i < a.length; i++) { if (a[i].paused) a[i].play(); } e = parent.querySelector('[data-autofocus="1"]'); x = e ? e.tagName : null; switch (x) { case 'FORM': e = e.querySelector('.field input, .field select, .field textarea'); if (e) e.focus(); break; default: break; } }, unloadElements = function (parent) { var a, e, x, i; a = parent.querySelectorAll('iframe[data-src=""]'); for (i = 0; i < a.length; i++) { if (a[i].dataset.srcUnload === '0') continue; a[i].dataset.src = a[i].src; a[i].src = ''; } a = parent.querySelectorAll('video'); for (i = 0; i < a.length; i++) { if (!a[i].paused) a[i].pause(); } e = $(':focus'); if (e) e.blur(); }; window._scrollToTop = scrollToTop; var thisURL = function () { return window.location.href.replace(window.location.search, '').replace(/#$/, ''); }; var getVar = function (name) { var a = window.location.search.substring(1).split('&'), b, k; for (k in a) { b = a[k].split('='); if (b[0] == name) return b[1]; } return null; }; var errors = { handle: function (handler) { window.onerror = function (message, url, line, column, error) { (handler)(error.message); return true; }; }, unhandle: function () { window.onerror = null; } }; loadElements(document.body); var style, sheet, rule; style = document.createElement('style'); style.appendChild(document.createTextNode('')); document.head.appendChild(style); sheet = style.sheet; if (client.mobile) { (function () { if (client.flags.lsdUnits) { document.documentElement.style.setProperty('--viewport-height', '100dvh'); document.documentElement.style.setProperty('--background-height', '100lvh'); } else { var f = function () { document.documentElement.style.setProperty('--viewport-height', window.innerHeight + 'px'); document.documentElement.style.setProperty('--background-height', (window.innerHeight + 250) + 'px'); }; on('load', f); on('resize', f); on('orientationchange', function () { setTimeout(function () { (f)(); }, 100); }); } })(); } if (client.os == 'android') { (function () { sheet.insertRule('body::after { }', 0); rule = sheet.cssRules[0]; var f = function () { rule.style.cssText = 'height: ' + (Math.max(screen.width, screen.height)) + 'px'; }; on('load', f); on('orientationchange', f); on('touchmove', f); })(); $body.classList.add('is-touch'); } else if (client.os == 'ios') { if (client.osVersion <= 11) (function () { sheet.insertRule('body::after { }', 0); rule = sheet.cssRules[0]; rule.style.cssText = '-webkit-transform: scale(1.0)'; })(); if (client.osVersion <= 11) (function () { sheet.insertRule('body.ios-focus-fix::before { }', 0); rule = sheet.cssRules[0]; rule.style.cssText = 'height: calc(100% + 60px)'; on('focus', function (event) { $body.classList.add('ios-focus-fix'); }, true); on('blur', function (event) { $body.classList.remove('ios-focus-fix'); }, true); })(); $body.classList.add('is-touch'); } })();
I don't think there is anything on my website that would require JavaScript and so naturally I am very confused. I am not very proficient at JavaScript and I was wondering if someone more knowledgeable than me could help me to interpret this code.
What does it do? Would my website still work if it was removed? Any comment is greatly appreciated.
-- WongSeo (talk to me!) 23:49, 17 August 2022 (UTC)
- TLDR: Pretty much harmless, unless it starts messing with Resource Loader or something that isn't supposed to be spitting out JavaScript.
- WongSeo, I pasted your code into an unminifier. It basically is:
- A bunch of variable declarations. (I have omitted some unused functions for brevity.)
on
is basicallywindow.addEventListener
,$
is basicallydocument.querySelector
,$body
is basically the<body>
tag of the documentclient
is a function:- From the code, it looks like it's trying to detect the browser.
- It initializes an object
o
to the value{ browser: "other", browserVersion: 0, os: "other", osVersion: 0, mobile: false, canUse: null, flags: { lsdUnits: false } }
- It sets the variable
ua
to the User Agent string, which is something likeMozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0
- Note: I'm saying "guess" because the user agent string can be faked and is not to be trusted. I actually fake my user agent when connecting to Wikipedia.
- It then tries a bunch of regexes on the user agent to try to guess if it is Firefox, Microsoft Edge, Safari, Google Chrome (note two regexes), or Internet Explorer.
- If any of those match, it searches for the first capturing group to guess the version.
- Then, it tries to guess the operating system name and version.
- Compatibility with browser styles is guessed and the o object is modified and returned.
- Then a bunch of unused functions
- Then,
scrollToElement
, which is basically a hyped up version ofelement.scrollIntoView()
. scrollToTop
is basically scrolling to the top of the page.loadElements
is a very... let's say questionable function. Here's what it does in a nutshell:- Blanks all
data-src
attributes from iframes after setting theirsrc
s to thedata-src
s. - Attempts to play all paused autoplaying videos.
- If the first element with a
data-autofocus
value of1
, it focuses the first text area, dropdown, or input inside that form.
- Blanks all
unloadElements
looks like an attempt to undo those.
- It then runs
loadElements
ondocument.body
. - It then inserts some weird CSS rules.
- Some badly designed user agent sniffing: If the OS version is before 11, insert some kind of CSS fix for some kind of browser bug.
- It sometimes adds
is-touch
classes, but I'm not sure when. - That's pretty much all there is to it!
- A bunch of variable declarations. (I have omitted some unused functions for brevity.)
- Hope this helps, weeklyd3 (block | talk | contributions) 05:02, 18 August 2022 (UTC)
- This is my first time posting at the reference desk so please tell me if I did something wrong. weeklyd3 (block | talk | contributions) 05:02, 18 August 2022 (UTC)
- @Weeklyd3, thank you so much! This helps out a lot. WongSeo (talk to me!) 15:19, 18 August 2022 (UTC)
- P.S. You did everything correctly. WongSeo (talk to me!) 15:19, 18 August 2022 (UTC)
- Actually, I don't think it is harmless. It starts adding a bunch of weird CSS classes based on your screen, which could really screw up your styling if something is special about htem. weeklyd3 (block | talk | contributions) 22:25, 18 August 2022 (UTC)
- This is my first time posting at the reference desk so please tell me if I did something wrong. weeklyd3 (block | talk | contributions) 05:02, 18 August 2022 (UTC)
- "I don't think there is anything on my website that would require JavaScript and so naturally I am very confused." Virtually all modern websites use JavaScript. It's standard practice. A Quest For Knowledge (talk) 09:49, 19 August 2022 (UTC)
- It's not compulsory and won't help with learning HTML. I use extensions when on a mobile browser to fake my user agent string and to prevent videos from autoplaying, and that's because of widespread excessive use of javascript like the above. Card Zero (talk) 14:00, 19 August 2022 (UTC)
- Most websites have some javascript because most websites are based on a small number of templates that use javascript. Big Tech is happy to provide such templates, because it allows Big Tech to do Evil Things. The scripts are rarely useful to website visitors, but the sites are built in such a way that they don't work without. Also considering how often I must install security updates for the javascript engine, I wonder why our politicians have made laws regulating cookies (which are fairly easy to defeat with browser settings), but not against excessive use of scripts. Please note the sarcasm. I don't follow the conspiracy theories, but I do worry that some parties have gained too much power over the internet. PiusImpavidus (talk) 09:20, 20 August 2022 (UTC)
- To be fair, if you want, say, a reply button that doesn't reload the page, you need Javascript. It does make it possible to manipulate a lot of things, unfortunately including people. Card Zero (talk) 12:08, 20 August 2022 (UTC)
August 20
How to download Symbola font version 14.0?
https://dn-works.com/ufas/ I can't find the download button. I am a Green Bee (talk) 10:28, 20 August 2022 (UTC)
- That's because you're a green bee. The first pdf on the page says "Fonts and documents are attached in the corresponding pdf files". This is hardly a convenient way to distribute them, and I wouldn't know how to extract fonts from pdf files, but those folks at Stack Overflow suggest several ways.
- In fact this online tool for extracting fonts did the job very conveniently. What you get is 55 fonts with meaningless names like ABAAAA+Symbola.ttf, ACAAAA+Symbola.ttf, etc., in a zip file.
- On the other hand, Windows says each file is "not a valid font file", although Fontforge can open them. (It can also extract then in the first place.) I told Fontforge to "generate fonts" and produce a ttf file, which resulted in something valid according to Windows, but it seemed messed up, with a lot of the glyphs missing when re-opened in Fontforge. I wonder if all the 50 or so files are supposed to be one big font file somehow? Maybe somebody should contact DimitriosDouro1 on Twitter and ask him what on earth the idea even is here.
- I successfully extracted (via Fontforge and then "generate fonts" of type Truetype) the one called KBAAAA+Symbola.ttf, which contains a lot of Byzantine musical symbols, so that's something. Card Zero (talk) 11:37, 20 August 2022 (UTC)
- @I am a Green Bee When you open the PDF in Firefox and look in the attachments tab, you see an OTF. I have uploaded it here: [1]. Just saying, it explained this here. – Berrely • T∕C 16:39, 20 August 2022 (UTC)
- Hmm, that's what I quoted from above, but "explained" is putting it strongly. So, pdf files can have "attachments"? I can't see them in Vivaldi. Card Zero (talk) 16:51, 20 August 2022 (UTC)
- @Card Zero yeah it's something I just learnt. I opened the PDF and noticed it in the tab. Seems to be an overly-complex method to be honest. – Berrely • T∕C 17:23, 20 August 2022 (UTC)
- Hmm, that's what I quoted from above, but "explained" is putting it strongly. So, pdf files can have "attachments"? I can't see them in Vivaldi. Card Zero (talk) 16:51, 20 August 2022 (UTC)
- @I am a Green Bee When you open the PDF in Firefox and look in the attachments tab, you see an OTF. I have uploaded it here: [1]. Just saying, it explained this here. – Berrely • T∕C 16:39, 20 August 2022 (UTC)
- That is a very weird download method, I've never heard of it before. Invisible in Safari, although it loads in Firefox. You might want to read this blog post by Anna Judson, which I've now finally got round to citing on Wikipedia, which mentions these fonts and the designer. It expresses the concern "the fonts are not licensed for any form of publication, academic or commercial [so best] if you only want these fonts for personal/teaching use", and suggests also trying the Noto fonts for that reason.
Personally, I find Noto Symbols can be very useful, and install it on all computers I use. Two font sets, Noto Sans Symbols for more common characters (this family has multiple weights) and this for more obscure ones (only one weight). Doesn't cover everything though, in particular I wish it has more arrow characters and chemistry symbols. Blythwood (talk) 20:31, 20 August 2022 (UTC)- It's normal to embed fonts in PDF. The PDF standard only specifies a handful of fonts that should be available to every PDF reader. For other fonts, you either have to gamble that the reader has the fonts installed (not very safe; even common Windows fonts like Arial are unlikely to be found on non-Windows computers), or you can embed the fonts in the PDF. Usually only the characters that are actually used in the document get embedded. If there are many symbol fonts of which only a few characters are used, that can save a lot of space.
- It's not normal to distribute fonts in this way. A legal loophole? PiusImpavidus (talk) 12:00, 22 August 2022 (UTC)
- embedding a font, as you say, makes it available for use the PDF, but it isn't readily saved (hence all the complicated extractors discussed above).
- attaching a file is different - the PDF format allows arbitrary files (of any type) to be attached to documents. These are readily saved (that's the intention of them).
- Of the files on the site I am a Green Bee lists, the Preview PDF has (fragments of) each font embedded, but it has no attachments. All the others have both the fonts embedded (using PDF's own font embedding mechanism) and the relevant OTF file attached.
- So they're using the PDF as both an illustration and a distribution mechanism. It's quite clever, but as this thread shows, file attachment in PDFs is sufficiently unusual that it's more likely to be confusing than helpful. -- Finlay McWalter··–·Talk 14:49, 23 August 2022 (UTC)
August 24
Online service to synchronize content on local computers
Is there a--preferably free--service to synchronize the content of a certain folder (incl. sub-folders) on three personal computers? We are working on a joint project and want to have the same files and same organization... but on our local computers (so we can work at hem offline and are in addition more independent of a cloud provider), not just on a cloud.
A solution entitely wihout a cloud (even as a means for synchronization) would be preferred, but I suspect that is even more unlikely to find?! ... Thanks for all suggestions, Ibn Battuta (talk) 08:01, 24 August 2022 (UTC)
- Perhaps Gitea or similar would fit the bill. --TrogWoolley (talk) 13:18, 24 August 2022 (UTC)
- Am I right to understand that Gitea is for software development? Do you know if it can be likewise used for just "any" content? (Our files are mainly Word documents, some spreadsheets, some images, etc.) Thanks, Ibn Battuta (talk) 19:22, 24 August 2022 (UTC)