Last active
January 18, 2021 15:47
-
-
Save Holofox/c7ba791d47d77df49661feb4dd635bd0 to your computer and use it in GitHub Desktop.
Hiding recoubs, mutes, non-hd, a.webm, vines and others coubs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name FRESHLY SQUEEZED COUBS | |
// @namespace https://holofox.ru/ | |
// @version 1.0 | |
// @description Hiding recoubs, mutes, non-hd, a.webm, vines and others coubs. | |
// @author Holofox | |
// @match *://coub.com/community/* | |
// @grant none | |
// ==/UserScript== | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js | |
(function($, undefined) { | |
$(function() { | |
const coubsSelector = '.coubs-list'; | |
/* Author @BrockA */ | |
function waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector) { | |
var targetNodes, btargetsFound; | |
if (typeof iframeSelector == "undefined") { | |
targetNodes = $(selectorTxt); | |
} else { | |
targetNodes = $(iframeSelector).contents() | |
.find(selectorTxt); | |
} | |
if (targetNodes && targetNodes.length > 0) { | |
btargetsFound = true; | |
targetNodes.each(function() { | |
var jThis = $(this); | |
var alreadyFound = jThis.data('alreadyFound') || false; | |
if (!alreadyFound) { | |
//--- Call the payload function. | |
var cancelFound = actionFunction(jThis); | |
if (cancelFound) { | |
btargetsFound = false; | |
} else { | |
jThis.data('alreadyFound', true); | |
} | |
} | |
}); | |
} else { | |
btargetsFound = false; | |
} | |
//--- Get the timer-control variable for this selector. | |
var controlObj = waitForKeyElements.controlObj || {}; | |
var controlKey = selectorTxt.replace(/[^\w]/g, "_"); | |
var timeControl = controlObj[controlKey]; | |
//--- Now set or clear the timer as appropriate. | |
if (btargetsFound && bWaitOnce && timeControl) { | |
clearInterval(timeControl); | |
delete controlObj[controlKey]; | |
} else { | |
if (!timeControl) { | |
timeControl = setInterval(function() { | |
waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector); | |
}, 300); | |
controlObj[controlKey] = timeControl; | |
} | |
} | |
waitForKeyElements.controlObj = controlObj; | |
} | |
function contentCallbackFunction(jNode) { | |
const masonrySelector = '.coubs-list__inner.masonry'; | |
const dataSelector = '.page:last-child .coub.coub .coub__inner .coub__vd .coub__viewer .viewer .contents .data'; | |
//--- Hide content | |
function hideContent(content) { | |
var elements = document.querySelectorAll(content); | |
$(elements).fadeTo(1000, 0.1); | |
} | |
//--- Tag Filtering | |
function filterTag(tags) { | |
return tags.map(a => a.title); | |
} | |
//--- Find matches | |
function containsAny(str, substrings) { | |
for (var i = 0; i != str.length; i++){ | |
for (var j = 0; j != substrings.length; j++) { | |
var substring = substrings[j]; | |
if (str[i].indexOf(substring) != - 1) { | |
return substring; | |
} | |
} | |
} | |
return null; | |
} | |
//--- Returns an array with the ratio | |
function ratio(val, lim) { | |
var lower = [0, 1]; | |
var upper = [1, 0]; | |
while (true) { | |
var mediant = [lower[0] + upper[0], lower[1] + upper[1]]; | |
if (val * mediant[1] > mediant[0]) { | |
if (lim < mediant[1]) { | |
return upper; | |
} | |
lower = mediant; | |
} else if (val * mediant[1] == mediant[0]) { | |
if (lim >= mediant[1]) { | |
return mediant; | |
} | |
if (lower[1] < upper[1]) { | |
return lower; | |
} | |
return upper; | |
} else { | |
if (lim < mediant[1]) { | |
return lower; | |
} | |
upper = mediant; | |
} | |
} | |
} | |
//--- Check coubs | |
function checkCoubs(nodes) { | |
var list = []; | |
let filter = ['a.webm','anime.webm','anime mix','vines','nightcore','моменты из аниме','приколы']; | |
let formats = [[5,4],[4,5],[3,2],[7,5],[14,25],[34,23],[37,24],[55,43],[17,18],[33,34],[22,23],[45,32],[44,31]]; | |
let coubs = document.querySelectorAll(nodes); | |
coubs.forEach(function(coub) { | |
var jsonData; | |
try { | |
jsonData = JSON.parse(coub.innerText); | |
} catch (e) { | |
console.log(e.message); | |
} | |
let format = ratio(jsonData.size[0] / jsonData.size[1], 50); | |
let fileVersion = jsonData.file_versions.html5; | |
let tags = jsonData.tags; | |
let mediaBlocks = jsonData.media_blocks; | |
let externalVideos = mediaBlocks.external_raw_videos; | |
if (!fileVersion.video.high || !fileVersion.audio || !tags.length || [format].map(a => formats.findIndex(b => a.every((v, i) => v === b[i]))) != -1 || | |
mediaBlocks.remixed_from_coubs.length || jsonData.audio_copyright_claim !== null || containsAny(tags.map(tag => tag.title), filter) || | |
(externalVideos.length && containsAny([externalVideos[0].title.toLowerCase()], filter))) { | |
//--- Add coub to list to hide | |
list.push('[data-id="' + jsonData.id + '"]'); | |
// console.log('Coub «'+jsonData.title+'» has been hided'); | |
} | |
}); | |
if (list.length) { | |
hideContent(list.join(','), true); | |
} | |
} | |
//--- Notify observer of adding new coubs | |
function addObserverIfDesiredNodeAvailable() { | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.type == 'childList') { | |
checkCoubs(coubsSelector + ' ' + masonrySelector + ' ' + dataSelector); | |
} | |
}); | |
}); | |
var targetNode = document.querySelector(coubsSelector + ' ' + masonrySelector); | |
if(!targetNode) { | |
window.setTimeout(addObserverIfDesiredNodeAvailable, 500); | |
return; | |
} | |
var observerConfig = { | |
childList: true | |
}; | |
observer.observe(targetNode, observerConfig); | |
} | |
addObserverIfDesiredNodeAvailable(); | |
} | |
waitForKeyElements(coubsSelector, contentCallbackFunction); | |
}); | |
})(window.jQuery.noConflict(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The most useful script that I only saw in my life. Thanks Holofox.