|
v1nce posted:regex101 is a great tool for explaining what's going on. I suggest you combine it with the above tutorials:
|
# ? Jun 5, 2015 11:19 |
|
|
# ? May 18, 2024 09:02 |
|
Can you get the http status code in img tag load event listener? You can use img.addEventListener('error', if the server's error response contains non-image data. But img.youtube.com returns an image in any case. The HTTP response is "404 OK" and the body of the response is this image: So using this code: JavaScript code:
If I change the img.src to "https://clowpenis.fart", imgerror is called.
|
# ? Jun 6, 2015 11:45 |
|
Is there a particular reason to avoid doing an XHR request on the image instead?
|
# ? Jun 6, 2015 12:41 |
|
Maluco Marinero posted:Is there a particular reason to avoid doing an XHR request on the image instead? It's a cross-origin request. Edit: but now that you mention it, it is a greasemonkey script and that can use GM_xmlhttpRequest, which apparently allows for it. Wheany fucked around with this message at 13:28 on Jun 6, 2015 |
# ? Jun 6, 2015 13:26 |
|
Might be a hacky overengineered fix, but you could compare a known 404 path image with the resulting img, but that'd be a pain in the rear end.
|
# ? Jun 6, 2015 23:02 |
|
Maluco Marinero posted:Might be a hacky overengineered fix, but you could compare a known 404 path image with the resulting img, but that'd be a pain in the rear end. This doesn't do anything to solve the cross-origin issues. If you can't make an XHR request to the image url, you can't get the image bytes from that url to compare them to anything else.
|
# ? Jun 7, 2015 05:01 |
|
I'm not able to test this right now (mobile), but images can be embedded freely, there's no preflight CORS involved in image embedding so surely...code:
...will give you access to the image file once it's loaded.
|
# ? Jun 7, 2015 05:31 |
|
Maluco Marinero posted:I'm not able to test this right now (mobile), but images can be embedded freely, there's no preflight CORS involved in image embedding so surely... You can embed them in the page, but you're not allowed to read back the actual image contents unless it's CORS-allowed (at which point you could just do an XHR).
|
# ? Jun 7, 2015 06:10 |
|
Besides, there is no redirect to compare to. The HTTP response is "404 OK" and the body is a valid image. Not that it matters anymore, since I just used a GM_xmlhttpRequest HEAD request to get the status code.
|
# ? Jun 7, 2015 07:03 |
|
Is there no way of knowing if the location has changed except for polling it? AFAIK, there are the events hashchanged that fires when the part after the # changes and popstate that fires when the user clicks the back button. But if a script modifies the location by using pushState or replaceState, no event is generated(?) Again, this is a Greasemonkey script, so if you're aware of anything there that accomplishes it, that would also help.
|
# ? Jun 7, 2015 07:15 |
|
I've been tasked with a project at work that is a bit outside of my skillset. I have most of it taken care of but I'm a bit stumped on one part. I have a webpage containing two strings that represent dates in the format of "MM/DD/YYYY HH:MM AM/PM". So I'll have:code:
Any ideas how I can easily compare those dates?
|
# ? Jun 19, 2015 02:10 |
|
Hughmoris posted:I've been tasked with a project at work that is a bit outside of my skillset. I have most of it taken care of but I'm a bit stumped on one part. I have a webpage containing two strings that represent dates in the format of "MM/DD/YYYY HH:MM AM/PM". So I'll have: code:
|
# ? Jun 19, 2015 02:30 |
|
^^^that Also for more advanced date parsing and comparisons, momentjs is a pretty good library.
|
# ? Jun 19, 2015 03:02 |
|
piratepilates posted:
Well, poo poo. My google skills are weak. Thank you.
|
# ? Jun 19, 2015 04:01 |
|
Parsing that particular date format is implementation-defined, I believe, so make sure that works on all your target runtimes
|
# ? Jun 19, 2015 06:02 |
|
Sedro posted:Parsing that particular date format is implementation-defined, I believe, so make sure that works on all your target runtimes I was a little worried since the application uses IE8 but it ended up working like a champ. I'm going to press my luck and ask a follow up question: How difficult is it to dynamically create checkboxes? When the webpage opens, I'll have a variable representing the amount of checkboxes needed. Currently I am just hardcoding the checkboxes, so sometimes I'll have an extra three or four that are taking up space and not needed.
|
# ? Jun 20, 2015 02:52 |
|
Hughmoris posted:I was a little worried since the application uses IE8 but it ended up working like a champ. JavaScript code:
|
# ? Jun 20, 2015 08:17 |
|
What's going on in variable declarations like this? (From a Firefox addon.)code:
|
# ? Jul 2, 2015 21:32 |
|
It's ES6 destructuring assignment equivalent tocode:
|
# ? Jul 2, 2015 21:43 |
|
Newf posted:What's going on in variable declarations like this? (From a Firefox addon.) It's object destructuring, new in ES6, combined with module import through the require function. The require function is returning an object (since the file it's referring to is exporting an object), and this code is using object destructuring to only bind one variable from it.
|
# ? Jul 2, 2015 21:46 |
|
Great, thanks. It declares a var whose value is the property on the right hand side with the same name. Doesn't exactly seem to be worth the mental energy of the switch, but I guess it's a harmless enough piece that forces luddites like me to read the new documentation. I decided to make a tiny firefox addon and it looks like I'm in for a bit of hurt. The 'require' here is the same as that at requirejs.org, yeah? For clarification, when something like require('jquery') is called, that doesn't find/load jquery proper, but rather an altered version which 'exports' jquery's '$', yeah? So calling something like code:
How can I get some tooling to parse / provide intellisense on these require-generated objects? Specifically, those belonging to the Firefox api? I've been poking around the FF add-on documentation but haven't seen a place to actually pull down the source for all of this stuff.
|
# ? Jul 3, 2015 00:02 |
|
Newf posted:Great, thanks. It declares a var whose value is the property on the right hand side with the same name. Doesn't exactly seem to be worth the mental energy of the switch, but I guess it's a harmless enough piece that forces luddites like me to read the new documentation. It's likely a CommonJS module rather than a requirejs type. More here: http://addyosmani.com/writing-modular-js/
|
# ? Jul 3, 2015 00:35 |
|
Newf posted:Great, thanks. It declares a var whose value is the property on the right hand side with the same name. Doesn't exactly seem to be worth the mental energy of the switch, but I guess it's a harmless enough piece that forces luddites like me to read the new documentation. quote:The 'require' here is the same as that at requirejs.org, yeah? Nope! RequireJS the package (RequireJS.org) is trying to accomplish the same goals but is a much more complicated way of doing it. The require() function is actually CommonJS, which isn't a package or runtime but a standard way of doing things. There's also no runtime for it directly, but you write it in the same style and different runtimes or packages will handle it the way you're expecting it to be handled. Node.js has an internal implementation of CommonJS whenever you run node on a javascript file, Browserify is a program that will interpret CommonJS imports and concatenate them in to one package, and there are a few others along the same lines. quote:For clarification, when something like require('jquery') is called, that doesn't find/load jquery proper, but rather an altered version which 'exports' jquery's '$', yeah? So calling something like Yes and no. jQuery by default when linked attaches $ to the global scope. Putting jQuery in to a form where it can be retrieved through require() lets you bind it to a variable anywhere you want without having it bound on the global scope. The destructuring there also isn't necessary and won't work, since jQuery's export will just be the $ object you do: code:
code:
code:
Doing var {$} = ... is trying to take the object returned by require('jquery') and binding the property named '$' (which doesn't exist I'm guessing) in that object to the local scope. Of course I'm just assuming that's how jquery's module is exporting, and for all I know you might be right.
|
# ? Jul 3, 2015 00:40 |
|
piratepilates posted:Of course I'm just assuming that's how jquery's module is exporting, and for all I know you might be right. I was just making assumptions as well, but yours are obviously better informed and more likely correct. It remains though: jquery itself doesn't export a module, but instead makes $ globally available. So when talking about the jquery require module, we're actually referring to someone's repackaging of jquery, right? Thanks again, both. I've made decent strides with js lately, but there always seems to be something totally foreign each new place that I look. e: I guess not? From jquery, JavaScript code:
Newf fucked around with this message at 02:13 on Jul 3, 2015 |
# ? Jul 3, 2015 02:07 |
|
I'm needing some help conceptualizing how I am going to layout my application. What I have is a screen mockup tool to drag/drop page layout and input elements. What I want to be able to do is preserve and save the design the user makes in a JSON file. This seems like it will be the easiest to accurately preserve a tree structure and read it back to re-render a previously saved state. I feel somewhat comfortable doing this in Angular if that helps at all. I basically made this whole thing a few years back using a lot of jQuery/jQueryUI spaghetti code of functions but I am trying to resurrect it into a better structured app. Any conceptual ideas/suggestions for structure would be much appreciated.
|
# ? Jul 3, 2015 16:19 |
|
excidium posted:I'm needing some help conceptualizing how I am going to layout my application. What I have is a screen mockup tool to drag/drop page layout and input elements. What I want to be able to do is preserve and save the design the user makes in a JSON file. This seems like it will be the easiest to accurately preserve a tree structure and read it back to re-render a previously saved state. I feel somewhat comfortable doing this in Angular if that helps at all. I've never done such a thing, but I would try anchoring each piece to its top left bounds, and then when redrawing use those as your points to stick the relevant piece into place. Someone with more knowledge than I should be able to answer you better, but that's what I would do in my limited experience. Perhaps one could make it more accurate by storing all four bounds.
|
# ? Jul 4, 2015 01:35 |
|
AuxPriest posted:I've never done such a thing, but I would try anchoring each piece to its top left bounds, and then when redrawing use those as your points to stick the relevant piece into place. The layout is pretty easy actually - everything is just HTML in a Bootstrap grid so everything is controlled by adding sections/rows. Adding a new element is as easy as appending it to its target.
|
# ? Jul 4, 2015 03:47 |
|
Is there some tool I can use to enforce a consistent house style? Having commits filled with switching back and forth between K&R and GNU indentation or whatever is driving me nuts (yes there are other workflow issues with people being able to just commit these to master without some sort of review but that's a different problem).
|
# ? Jul 5, 2015 21:11 |
|
RICHUNCLEPENNYBAGS posted:Is there some tool I can use to enforce a consistent house style? Having commits filled with switching back and forth between K&R and GNU indentation or whatever is driving me nuts (yes there are other workflow issues with people being able to just commit these to master without some sort of review but that's a different problem). You can use JS Beautifier which has plugins for all the major text editors/IDEs. Just setup a configuration in a .jsbeautifyrc file that follows the team's standards and have everyone use it!
|
# ? Jul 5, 2015 21:25 |
|
RICHUNCLEPENNYBAGS posted:Is there some tool I can use to enforce a consistent house style? Having commits filled with switching back and forth between K&R and GNU indentation or whatever is driving me nuts (yes there are other workflow issues with people being able to just commit these to master without some sort of review but that's a different problem). We use eslint-- it has a crazy array of rules you can use to define exactly how your code should be styled (along with the other things you'd expect from a linter) http://eslint.org/docs/rules/
|
# ? Jul 5, 2015 21:47 |
|
Wow, two good suggestions, thanks.
|
# ? Jul 6, 2015 01:29 |
|
Fish Ladder Theory posted:We use eslint-- it has a crazy array of rules you can use to define exactly how your code should be styled (along with the other things you'd expect from a linter) Holy this has come a long way.
|
# ? Jul 6, 2015 22:31 |
|
I have a stupid angular question. I'm trying to get program ID from ng-init, but it's undefined because reasons. I can dump the scope object and the value is defined in the object, with the correct value, however trying to access it doesn't work.code:
code:
|
# ? Jul 17, 2015 13:11 |
|
Be careful with logging $scope and interpreting the result - the behaviour of the debugger can be more confusing than enlightening. Specifically, the log will show you the value of the $scope object when you clicked the arrow to expand it, not what the value was when the log statement ran. Chances are the id is being set sometime after this code runs.
|
# ? Jul 19, 2015 04:17 |
|
Jabor posted:Be careful with logging $scope and interpreting the result - the behaviour of the debugger can be more confusing than enlightening. Specifically, the log will show you the value of the $scope object when you clicked the arrow to expand it, not what the value was when the log statement ran. I'm just irked with the inconsistency more. I've run into things like this with JS many times in the past. I just went through everything and changed methods to make sure everything runs after the page loads. Everything is fine and back to normal.
|
# ? Jul 19, 2015 17:20 |
|
Long story short, I downloaded some Chinese bloatware. I couldn't figure out how to uninstall because the characters wouldn't load properly on my capitalist dog windows 7, so I ended up just deleting the whole thing. Now instead of a javascript iframe with advertisements for handbags and iphones, it's just an empty box. Does anyone know where the root of this would be? I can see the javascript when I open up firebug, but I don't know how to make it stop.
|
# ? Jul 20, 2015 05:56 |
|
"Flatten and reinstall" is usually the best course of action when cleaning up malware. Back up anything you want to keep first, of course.
|
# ? Jul 20, 2015 10:09 |
|
nickmeister posted:Long story short, I downloaded some Chinese bloatware. I couldn't figure out how to uninstall because the characters wouldn't load properly on my capitalist dog windows 7, so I ended up just deleting the whole thing. Now instead of a javascript iframe with advertisements for handbags and iphones, it's just an empty box. Does anyone know where the root of this would be? I can see the javascript when I open up firebug, but I don't know how to make it stop. Write an extension that overwrites the functions of their JS. OK, not really. But I don't think your uninstall worked. Why not try malware removal tools?
|
# ? Jul 23, 2015 03:44 |
|
nickmeister posted:Long story short, I downloaded some Chinese bloatware. I couldn't figure out how to uninstall because the characters wouldn't load properly on my capitalist dog windows 7, so I ended up just deleting the whole thing. Now instead of a javascript iframe with advertisements for handbags and iphones, it's just an empty box. Does anyone know where the root of this would be? I can see the javascript when I open up firebug, but I don't know how to make it stop. Before you flatten and reinstall, I'm actually curious: ctrl shift a -> plugins, anything?
|
# ? Jul 23, 2015 04:09 |
|
|
# ? May 18, 2024 09:02 |
|
What's the plan on module support in the browser? How's that going to work? I mean, I know how to do it right now with something like webpack or browserify, but I assume eventually browsers will support doing something with the import keyword.
|
# ? Jul 23, 2015 19:03 |