FIMFiction UserScripts 383 members · 0 stories
Comments ( 6 )
  • Viewing 1 - 50 of 6
knighty
Site Owner

Whether these work will of course depend on whether your Javascript is running in page scope or sandboxed. I haven't done user script work in years so I don't know whether this post will actually apply to anyone...


App.AddBinder(callback);

The callback will be called any time anything makes a change to the DOM with the only argument being the node that should be bound. You can use this to, for example, do something with comments when the comment page is changed.

fQuery.addScopedEventListener(node, selector, event, func, capture) ;

You can use this to bind an event a dom element higher in the tree to avoid needing to bind on the element itself. For example you could use:

fQuery.addScopedEventListener(document.body, "a", "click", function() { 
	console.log(this.href);
}

To output the href of any link that is clicked. There's a lot of other jQuery type functions as well in there you can use.

class fQuery {
    static ready(func);
    static createFromHtml(html);
    static addScopedEventListener(node, selector, event, func, capture = false);
    static removeScopedEventListener(node, event, func, capture = false);
    static isOrChildOf(node, parent);
    static closestParent(node, selector) ;
    static siblings(node, includeSelf = false);
    static addClass(nodes, className);
    static removeClass(nodes, className);
    static toggleClass(nodes, className, force);
    static css(nodes, property, value);
    static insertAfter(after, node);
    static insertBefore(before, node);
    static prepend(to, node);
    static removeElement(element);
    static removeElements(elements);
    static scrollTop(val = null, absolute = false, animate = null);
    static scrollTo(element, animate = null);
    static scrollLeft(val = null, absolute = false);
    static text(element);
    static nodesToArray(nl);
    static animateProperty(setter, from, to, duration, curveFunction = null);
    static debounce(func, wait, immediate);
    static throttle(func, wait);
    static loadScript(url);
    static animationFrame(callback, max);
    static disableScroll();
    static enableScroll(handle);
    static removeChildren(node)
}

Ajax Requests are simple enough too.

new AjaxRequest({
	url : "/endpoint",
	method: "POST",
	data: { foo: "bar" },
	signed: doesThisEndPointNeedSignedData,
	success: function(data) {
		console.log(data);
	},
	fail: function(error) {
		console.log(error);
	}
});

If you need any help with any of the fQuery stuff I can help answer, but it should avoid the desire for using jQuery in general.

ssokolow
Group Contributor

Whether these work will of course depend on whether your Javascript is running in page scope or sandboxed. I haven't done user script work in years so I don't know whether this post will actually apply to anyone...

Running it in page scope is the default these days, because it simplifies interacting with site JavaScript APIs as sites become more and more AJAXy, so they should be fairly useful to people.

knighty
Site Owner

5981374
That's good to know then. Ideally I'd say everyone should try and stay away from including jQuery in their scripts. The difference we've seen in performance due to me rewriting the codebase is truly staggering. It's even easier to write user scripts with native JS too because you don't have to worry about supporting crappy browsers like I do 😛

ssokolow
Group Contributor

5981429

*nod* If I can ever find time to go through my old scripts and bring them up to spec (test suites and TypeScript rewrites), I'll definitely be replacing jQuery with use of modern APIs.

As-is, I'm just glad that all of my fimfic tweaks were made as Userstyles specifically to give the browser maximum ability to optimize for performance.

Selbi
Group Admin

When I first discovered jQuery, everyone was seemingly prasing as the best thing since sliced bread. Now everyone says to stay away from it as much as you can. Longevity certainly isn't a thing in the world of IT.

knighty
Site Owner

5981779
jQuery's still good if your requirements are extreme compatibility and legacy support. Fimfiction isn't a government website though and that means we can logically drop support for a lot of those old browsers which frees us up to use much more performant native Javascript. Also Javascript is just way more fleshed out and more powerful nowadays than it used to be.

  • Viewing 1 - 50 of 6