Instagram Video Fixer
Fixes Instagram video behavior
This script is marked as "external"This script was commisioned by someone else, and I will not check if it works. If it breaks,
contact me Click here to install
Browse More Scripts
// ==UserScript==
// @name Instagram Video Fixer
// @namespace ef780323b1b0ddb8d0377b67d7a5f78ebf65b83f
// @version 0.2
// @description Fixes Instagram video behavior
// @author /u/AyrA_ch
// @include https://*.instagram.com/*
// @include https://instagram.com/*
// @grant none
// @external true
// ==/UserScript==
(function ($$) {
//List of items to remove
var removals = ["a.QvAa1", "div.oujXn", "img._8jZFn", "div.PyenC", "div.fXIG0"];
var log = function () {
args = ['Instagram Fixer'].concat(Array.prototype.slice.call(arguments));
console.debug.apply(console, args);
};
//Cancels a user event
var cancel = function (e) {
//e.preventDefault();
e.stopPropagation();
};
//Event that updates the volume across all videos
var volumeChange = function (e) {
var vol = (e.target.volume * 100 | 0) / 100;
$$("video").forEach(function (v) {
if (v !== e.target) {
v.volume = vol;
}
});
localStorage.setItem("video_volume", vol);
};
//Get volume from storage
var getVolume = function () {
var v = +localStorage.getItem("video_volume");
return v == v ? v : 1;
};
//Fix page in response to changes
var fixPage = function () {
removals.forEach(function (v) {
$$(v).forEach(function (v) {
log("Removed element", v);
v.remove();
});
});
Array.prototype.filter.call($$("video"), function (v) {
return !v.controls;
}).forEach(function (v) {
//Clone the video element to kill all associated events
var n = v.cloneNode(false);
v.parentNode.appendChild(n);
v.parentNode.removeChild(v);
n.controls = true;
n.preload = "meta";
n.volume = getVolume();
n.addEventListener("volumechange", volumeChange);
n.addEventListener("play", function (e) {
var current = e.target;
$$("video").forEach(function (v) {
if (v !== e.target && !v.paused) {
log("Pausing", v);
v.pause();
}
});
});
log("Attached volume event to", v);
});
};
//Trigger initial fix
fixPage();
var mo = new MutationObserver(fixPage);
mo.observe(document.body, {
subtree: true,
attributes: true,
childList: true
});
})(document.querySelectorAll.bind(document));
/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.
DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
This script is marked as "external".
This means that the script was developed for someone else.
Because I don't use the script myself I will not know when it breaks.
If it breaks,
contact me for a fix.
User Script Managers
A userscript manager is the browser extension that injects scripts into websites
to change their behavior to your liking.
Recommendation
All scripts on this site have been developed and tested with Tampermonkey on firefox.
Try other browsers and other script managers at your own risk.
No script should use firefox or chrome specific features,
which means they should also work in other modern browsers.
If you prefer, you can use greasemonkey.
Get Tampermonkey,
Get Greasemonkey (Firefox only)
Script Installation
Once you have obtained a user script manager,
clicking on the install button will pop up an installation prompt.
To allow script manager detection,
you can install this helper script.
It's not necessary but simplifies your future visits to this site.
Script Installation
We detected, that you have a script manager installed and active.
Click the "Install Script" button to obtain the script.