Run javascript code each time a page is opened - javascript

I often find myself using this line of code on the console of the browser:
document.getElementsByTagName('video')[0].playbackRate = 1.5;
I use it so I can speed up a video (I just prefer to watch videos on a higher speed). Is there a way to make this line of code run on every web page I open. For example if I go to a youtube video, this line of code runs automatically. I know that YouTube already has buttons for speed, but some players don't have the UI for this and this is why I have to do this often. Thanks in advance :)

Related

Infinite image scrolling with instafeed.js

I want to integrate a simple slider that scrolls to the latest 20 images from an instagram account on a website. The image implementaion via instafeed.js is working, but the scrolling won't work. I used a third-party jquery based animation for this too, but I can't get it working with the loaded insta images.
The first thing that is not working, is the automated scrolling. Sometimes it works, but only in chrome's debugging mode.
The second thing is, that the slideshow does not loop. It should repeat when the last image scrolls in.
I have uploaded the files here: Files as download
I would be so happy, if you can help me with this problems. They are driving me crazy :D
I got it working by setting a small timeout to allow the page to finish running your other scripts before starting the scroll.
setTimeout(function(){
$("#instascroller").scrollForever();
},1000);
This code is in init.js It's just a small wrapper where you already call scollForever().
Testing your provided example in chrome I was unable to reproduce the bug where the slideshow doesn't loop. It is working fine for me.

Javascript game does not load sprites but loads arena

https://github.com/mliu95/quintus-tag
Source code is there.
I was following Liu's tutorial on this (https://mliu95.github.io/2014/09/16/Creating-an-online-multiplayer-web-game-using-Socketio-and-Quintus-Part2/)
Part 1 worked perfectly fine (single player with a movable sprite). However, upon introducing multiplayer (accomplished by opening multiple windows with localhost:8080), the sprites simply don't appear on the screen.
Also, you are dealing with a complete noob in terms of networking. I know a decent amount of Java but have no experience whatsoever. Any advice would be greatly appreciated.
You didn't give much information to go on, and didn't respond to my question in the comments that could clarify the issue.
But here is what I think is happening, in part one of the tutorial he lists his sprite paths here:
var files = [
'/images/tiles.png',
'/maps/arena.json',
'/images/sprites.png',
'/images/sprites.json'
];
I'm assuming your sprites are 404'ing (not being found), so here is a possible fix.
Your file structure is probably not the same as his, where are you storing the sprite images locally (on your pc)? It needs to be in the same paths as shown above. Sprites should be located in YourProjectFolder/images. Make sure your your sprite file is named sprites.png
After making sure all those files are placed correctly, open your developer tools (f12), head to the network tab, check the "disable cache" box (if you're on chrome). And refresh.
It should load your sprites after these changes, and if not, you need to post the specific errors you are running into. The errors will show up in developer tools after you refreshed, if it is still unable to find them.
Good luck

My sounds are not playing in Chrome

I have a small, very basic 3d game that runs in all browsers. But my issue is that when it runs in Chrome I can see in my console messages that the sounds are "pending" and don't play when they should. The thing is that after some time have passed ALL sounds play at the same time. It doesn't seem to be happening anywhere else, its just in Chrome. I came across this article that someone posted but it did not solve my issue. Just in case I am running Version 43.0.2357.81 m of Chrome and I am using the Sound Manager 2 library (I needed it in order to have sound work with IE 9 and up).
Can anyone offer some suggestions or point me to any more articles that might point me to a solution? Many thanks in advance!
Turn on logging in Chrome (inspect element/console - Preserve log) and see what your code is doing.
Also, you could try enabling/disabling your audio flags just be sure to set them back to default when you are done.
chrome://flags/#disable-encrypted-media
chrome://flags/#disable-prefixed-encrypted-media/
chrome://flags/#try-supported-channel-layouts
chrome://flags/#enable-delay-agnostic-aec
chrome://flags/#disable-delay-agnostic-aec
chrome://flags/#enable-tab-audio-muting
in chrome and see if that makes a difference.
Just shooting from the hip on the information given though, I would imagine that chrome is delaying your audio javascript execution to the end of the page load. Moving the script to the beginning of the page, or using an async could fix this. Here is a good resource for javascript page load issues: http://www.html5rocks.com/en/tutorials/speed/script-loading/

Animation runs slower and doesn't replay without page reload in chrome

Hi I'm following a tutorial in using easelJS for writing browser based games. And the tutorial is going fine but I've noticed some problems whilst playing the animations on chrome.
Chrome runs the animations slower and once played through once the same animation will not play again unless I reload the page.
Running in Firefox it doesn't have any of these problems.
Here's the link: (use inspect element for code)
http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial03.html
I've heard there are some caching problems in chrome so I thought this might be the problem.
Manually deleting the cache does in fact allow the animation to play again without a page reload, but it still runs slowly (compare it to firefox).
As I want to code for cross browser compatibility is there a supported way in chrome to combat these problems? Such as blocking storing the images in cache or something? (A last resort I hope)
Thanks in advance,
Kyohei
EDIT: It seems the speed of the animation is the same on ie10 so not sure what speed it should be you know.
The reason this will not work after a "reset" is that you are relying on the image load events to kick off the animation. This will work the first time, but the second time, the image is already loaded, and therefore you will never get an onload event from the images (meaning no "startGame()".
Since this is a simple example, maybe the best approach is to create new Images each time. Just move these lines into your init:
function init() {
var imgMonsterARun = new Image();
var imgMonsterAIdle = new Image();
// Other stuff
}
i read an article Fix your Timestep it will help you , just need to convert it to javascript , read it carefully .

HTML5 embed tag - event attributes not firing (onended, onpause etc)

I've searched for many hours trying to find a solution to this problem. I have a HTML5 web page with a background sound file that plays automatically when the page loads, and I'm trying to get a function to run when the sound file finishes playing. I've isolated the code I'm using into a test file to ensure nothing else is causing the problem. The sound plays fine in Firefox (which I'm using to test). From the many solutions I've tried, it seems as though the event attributes in the embed tag simply aren't firing at all.
Here is the test HTML page I'm using (tried putting HTML in here but it wouldn't show up properly, I know it's probably a noob error but I'm in a hurry with this):
Testpage
As you can see the message function works fine, as the "TEST" link indicates when clicked. But the messages for the media events don't appear.
If anyone can help me with this, I'd be most grateful as it's for a time-critical company project. I'd be happy to try alternative solutions to the event attributes, as long as I can get my own Javascript function to run on the sound file reaching its end, I'll be happy!!
Thanks!
Billy
Since you're using HTML5, it would be better to use the <audio> tag rather than <embed>. This works fine in my example:
http://jsfiddle.net/u6dbV/
You can include HTML here, but it has to be marked up as code or it'll get stripped out.

Categories

Resources