Custom javascript in WriteFreely 0.81

Created a local Windows 10 Development install of WriteFreely 0.81 to get familiar with it.

On the Customization page, I see how to input Custom CSS, but I don’t see anything for entering custom Javascript. Does this capability exist in WriteFreely 0.81?

There’s no way to use custom Javascript in WriteFreely 0.8.1.

I left it out to prevent security issues that might come up on multi-user instances. But are you running a single-user instance?

Yes, a single-user instance on a local machine with sqlite3, I might use it for keeping track of notes, references, links, to-do list items, items I won’t post online, etc. Got it up and running with no issues, instructions were very helpful.

Maybe this can be an option for admin on a per instance (or per blog) basis. Personally I use JS on Write.as to insert non-breaking spaces used by French typographic rules… Very useful.

2 Likes

I made a post on one of my blogs about custom JavaScript and French typography in Write.as… obviously it’s in French :sunglasses:

2 Likes

Thanks for posting, Aris. I found that https://translate.google.com did a good job of converting it to English.

1 Like

Hi, I just set up a single instance blog on my VPS with WriteFreely… Can I place some JS into a template file or something? I am going to be poking around myself but thought I would ask if there was a best practice first.

Great blogging software! I love the ease of use and minimalist approach.

1 Like

I eventually just put my JS snippet into every template file and restated WF. It seems to have worked. I was trying to find a “footer” template (or any “every page” template) but nothing I found seemed to include the script on every page so I gave up and just put it everywhere. Not super-helpful to anyone else but hopefully, someone will figure out how to do this better than I have.

1 Like

Hey, sorry I never got back to you earlier. It’s true the templates aren’t really set up for this right now.

I think ultimately we’re moving towards having common elements like this stored in the database and editable from the admin interface – and ideally supporting this by v1.0. So if you don’t mind sharing, what was the JS for? This will help inform what kind of capabilities we build.

Hi Matt, the JS was Google Analytics tracking code. I get NO traffic but I like to have analytics there just for fun. I am a web developer, though, and would like to have a way to add on JS I write if I want to make a custom widget or something for the front end.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXX-1');
</script>

Sorry to dig up an old thread, Matt - but I am just looking for the same possibility of running light javascript in some WF pages.

I imagined it was off for security reasons; and asked my gracious host, at https://write.tedomum.net/ for assistance. They pointed me to this thread.

I have a very short script which is useful for a Custom Google Search engine, strictly for my own blog pages. It works well, but would be ideal if this could be an option - allowed in the Settings panel, possibly?

It might be shown in the footer of every page, and the user configurable parameter would be simply the string of characters cx, that defines the specific page as added by the user to GCSE. This code is what I need :

`<script async src="https://cse.google.com/cse.js?cx=3e384e93bce23813b"></script>`
`<div class="gcse-searchbox"></div>`

and the results area below :

`<div class="gcse-searchresults"></div>`

Thank you !

Are script includes on the roadmap? I checked Phabricator but didn’t see it there.

I’m mostly interested in including an analytics script tag (not GA).

I managed to sneak my analytics JS code into the end of the Custom CSS box by ending the </style> tag, adding the JS and then opening another <style> tag.

e.g.

/* custom CSS */
</style>

<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
	a[h]=a[h]||function(){
		(a[h].q=a[h].q||[]).push(arguments)
	};
	o=f.createElement('script'),
	m=f.getElementsByTagName('script')[0];
	o.async=1; o.src=t; o.id='fathom-script';
	m.parentNode.insertBefore(o,m)
})(document, window, '//fathom.domain.com/tracker.js', 'fathom');
fathom('set', 'siteId', 'ABCDE');
fathom('trackPageview');
</script>
<!-- / Fathom -->

<style type="text/css">
/* closed by the code which injects the custom CSS */
4 Likes

OMG, I LOVE THIS!! THANKS YOU VERY MUCH! :heart:

I just tried @infuerno hack and it is a very good shortcut to add plausible to a specific blog without creating a breach on drafts. thanks very clever and simple.

anyone has tried to add cusdis with @infuerno 's hack?

I m trying to doing with this method, but it is not working for me

Hi @matt i hope you are well. I would like to know, why is there no custom javascript for single-user instances?

Best regards