inject css file with def.json


JimMorrison723

Recommended Posts

I am having the same issue, but the answer here is not good for me for some reason. "actions": ,

"type": "script",

"icon": "icon",

"include" : ,

"css" : ,

"js" : ,

"includeFrames": falseIt injects the js files, but they are not formatted, and i can even check if the styles are loaded. When i try to load a css file from js file like this:$('title').append('');It saysNot allowed to load local resource: mxaddon-pkg://{...}/css/content.css I have no idea why. I coudn't inclide images either, so i used data:image(... :( ), but i really need to inject these css files.

P.S: I know there was a question before this about this problem, i just coudn't write there.

Link to comment
Share on other sites

There are different ways to inject css file. First, read the documentation Javascript API page 15.

"var mxRuntime = window.external.mxGetRuntime(),

mxStorage = mxRuntime.storage,

mxBrowser = mxRuntime.create("mx.browser"),"

OR

"var mxstorage = null;

var rt = window.external.mxGetRuntime();

mxstorage =

{here your js code}

var browser = rt.create('mx.browser');

"

all depends of you .js file.

CSS can be included too as :

var css = "your css code";

var style = document.createElement('style');

style.setAttribute('type', 'text/css');

style.appendChild(document.createTextNode(css));

document.getElementsByTagName('head').appendChild(style);

document.addEventListener('DOMContentLoaded', function () {

var XXX= "xxxx";

You must know, html, css, js and jQuery

Without this knowledge, you can wait years and hope. Perhaps now works.

P.S Maxthon isn't Firefox or Chrome. js,css injection and storage is different.

Mx4-Extension-SDK-1.0.6-Documentation.zip

Link to comment
Share on other sites

Positronis replied at 2014-7-2 11:32 back.gif

There are different ways to inject css file. First, read the documentation Javascript API Site 15.

...

First of all, thank you for your reply.

It is working now, but i still don't understand why it doesn't load css from def.json. And why i can't do this:$('head').append('');I even have problem with images, the same. I had to convert images to data:image... Getting extension url, then add the image url of this works like a charm in every browser (ok, i get this is a little different browser, but same core), expect this one.

My extension have 5-6k lines of Jquery code, and a few hundred lines of style in css files. It was a pain in the ass to port from chrome, even it's also uses webkit/blink. Starting with localstorage, you have to use different syntax to get or set a key. In chrome you can use:

datastore = true;

if(datastore == false)...

So much nicer and better... And Chrome's, Opera's, Firefox's own def.json (manifest.json,...) works properly, if i say load that freakin css on that page it loads the freakin css file.

I just started using Maxthon this week, just to port my extension for those who wants it, but they are using this browser. When i will finish my work i hope they will be really, really appreciate it...

Link to comment
Share on other sites

JimMorrison723 replied at 2014-7-3 10:48 back.gif

First of all, thank you for your reply.

It is working now, but i still don't understand why it doe ...

Hi,

Not allowed to load local resource: mxaddon-pkg://{...}/css/content.css

Please read my post once again and read the documentation Javascript API page 15. This error is local storage problem.

You need

"var mxRuntime = window.external.mxGetRuntime(),....................."

I had to convert images to data:image... Getting extension url, then add the image url of this works like a charm in every browser (ok, i get this is a little different browser, but same core), expect this one.

Image to base64 converter

Your code will be: 'data:image/png;base64,xxxxxxxxxx'; or 'data:image/gif;base64,xxxxxxxxxx'; or 'data:image/jpeg;base64, xxxxxxxxxx';

"When i will finish my work i hope they will be really, really appreciate it..."

I hope too.

Here is attached my modified "Maxthon Extension Package Tool 1.0.0.7" nothing is modified, only the look and buttons.

post-11090790-14315120092017_thumb.png

post-11090790-14315120093161_thumb.png

Maxthon Extension Package Tool 1.0.0.7.zip

Link to comment
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.