Alshain How can I Jquery run every pages&posts&homepage etc.?
I'm not quite sure what you want to do. I assume you want to have jquery being executed with every new page load. If my assumption is correct you can do this by extending or overriding the prototype of a given page.
If you have no idea about writing extensions you may read here more about it:
https://flarum.org/docs/extend/
Now let's assume, your extension helloworld is here:
flarum/packages/helloworld
To work with jQuery, you need to work on the Javascript side of things:
flarum/packages/helloworld/js/src/forum/index.js
This file could look like this to have jQuery code executed with each visited index page (all discussions, tag view):
import app from 'flarum/app';
import {extend} from 'flarum/extend';
import IndexPage from 'flarum/components/IndexPage';
app.initializers.add('helloworld', function() {
extend(IndexPage.prototype, 'view', function (view) {
$('body').addClass('hello-world');
});
});
The executed jQuery function does only one thing: it adds a class to the body element named hello-world. It's not a fancy extension, but here you have a jQuery code executed only with index pages. You can check this by going to a non-index page, reload the page, inspect the body element and then move to an index page.
Keep in mind, that moving away from the index page doesn't remove the class, this has to be done actively by extending the prototype of another kind of page, e.g.
import app from 'flarum/app';
import {extend} from 'flarum/extend';
import IndexPage from 'flarum/components/IndexPage';
import UserPage from 'flarum/components/UserPage';
app.initializers.add('helloworld', function() {
extend(IndexPage.prototype, 'view', function () {
$('body')
.addClass('hello-world');
});
extend(UserPage.prototype, 'view', function () {
$('body')
.removeClass('hello-world')
.addClass('hello-user');
});
});
I have not tested this code, I hope it's not too faulty.
At least you get an idea how to add jQuery code to certain types of pages.