Snippets
Created by
Idoenk . Heri Purnomo
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | // ==UserScript==
// @name GDriveThumnailScrap
// @description GDriveThumnail video user script
// @author Provetic
// @namespace provetic/fbext
// @homepageURL https://greasyfork.org/en/scripts/XXXXX
// @icon https://dl.dropbox.com/s/j3vuagrdc6yte8s/glarge96-min.png?dl=0
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @include /https?:\/\/videoarsip-wp\.test\/*/
// @include /https?:\/\/media\.tnkdp\.id/*/
// @version 0.1
// @timestamp 1530531966704
// @grant GM_log
// @grant document-end
// ==/UserScript==
/**
* RTFM
*
* Use this additional params in URL for particular purpose:
*
* Eg. www.instagram.com/jokowi
*
* window.alert(new Date().getTime());
*/
(function() {
function main_script($){
'use strict';
// Global Variables
var gvar = function(){};
gvar.__DEBUG__ = 1;
gvar.version = {
number: '0.1',
timestamp: '1530531966704'
};
gvar.root_selector = '#UseyourDrive';
gvar.root_player = gvar.root_selector+' .jp-jplayer';
gvar.thumbnail_link = '';
gvar.observe_timeout = 35;
gvar.stIDomWatch = null;
// ============================
var KS = 'KEY_SAVE_',
GMSTORAGE_PATH = 'GM_',
OPTIONS_BOX = {
KEY_SAVE_URL_SEARCH: [''],
KEY_SAVE_BULK: ['']
}
;
function GM_addGlobalStyle(a, b, c) {
var d, e;
if (a.match(/^https?:\/\/.+/)) {
d = createEl("link", { type: "text/css", rel:'stylesheet', href:a });
}else{
d = createEl("style", { type: "text/css" });
d.appendChild(createTextEl(a));
}
if (isDefined(b) && isString(b)) d.setAttribute("id", b);
if (isDefined(c) && c) {
document.body.insertBefore(d, document.body.firstChild)
} else {
e = document.getElementsByTagName("head");
if (isDefined(e[0]) && e[0].nodeName == "HEAD") setTimeout(function () {
e[0].appendChild(d)
}, 100);
else document.body.insertBefore(d, document.body.firstChild)
}
return d
}
function _show_alert(msg, force) {
if (gvar.counter)
gvar.counter++;
else
gvar.counter = 1;
// Emulated GM_Log suck showing real value of object
if (gvar.ApiUpgrade){
if (!(typeof msg == 'number' || typeof msg == 'string'))
msg = JSON.stringify(msg);
}
if("function" == typeof GM_log){
var isText = (['string','number'].indexOf(typeof msg) !== -1);
GM_log("(" + gvar.counter + ") " + (!isText ? "[OBJ]" : msg));
if( !isText )
GM_log(msg);
}
else{
if( console && console.log ) console.log(msg);
}
if( !force )
return !1;
}
//=== mini-functions
// static routine
function isDefined(x) { return !(x == null && x !== null) }
function isUndefined(x) { return x == null && x !== null }
function isString(x) { return (typeof(x)!='object' && typeof(x)!='function') }
function trimStr(x) { return (typeof(x)=='string' && x ? x.replace(/^\s+|\s+$/g,"") : '') }
function clog(x){
if( !gvar.__DEBUG__ )
return !1;
_show_alert( x );
}
function createTextEl(a) {
return document.createTextNode(a)
}
function createEl(a, b, c) {
var d = document.createElement(a);
for (var e in b) if (b.hasOwnProperty(e)) d.setAttribute(e, b[e]);
if (c) d.innerHTML = c;
return d
}
// ====
// templating & assigning events
function design(){
let $root = $(gvar.root_selector);
var wH = $(window).height(),
treshold = 70,
$title = $('title'),
selectMe = function(){}
;
// css-ing
var buffCSS,
tpl = '',
CSS = ''
// Hider (last-resort)
+'#hide{display: none!important;}'
+'.wrap_thscraper{position:relative; text-align:center; border-bottom: 2px; border:1px solid green;}'
+'.thumbnail-link{width: 100%; padding: 6px 10px!important; font-size: 12px; font-family: courier, monospace;}'
+'.button.download-thumbnail-link{margin-top: 10px!important;}'
+'.button.download-thumbnail-link:hover{color: #fff!important;}'
;
GM_addGlobalStyle(CSS, 'gdrv-css-styles');
tpl = ''
+'<div class="wrap_thscraper">'
+ '<p>Thumbnail-url</p>'
+ '<input type="text" class="thumbnail-link" readonly="readonly" value="'+gvar.thumbnail_link+'" />'
+ '<a href="'+gvar.thumbnail_link+'" class="button download-thumbnail-link" target="_blank">View</a>'
+'</div>'
;
$root.append(tpl);
// -=-=-=
// Events
$root.find('.thumbnail-link').on('click', function(){
$(this).focus().select();
});
}
function main(){
clog('Initialize...');
// Invalidate oberser
if (gvar.observer){
clog('Disconnecting observer..');
try{
gvar.observer.disconnect();
}catch(e){}
}
setTimeout(function(){
var $root = $(gvar.root_selector),
$playlist = $root.find('.jp-playlist'),
offset = 0
;
if ($playlist.length)
offset = $playlist.offset();
$('html,body').animate({scrollTop: offset.top}, 0, function(){});
}, 1521);
clog('Design..');
design();
}
// Observe any change in given element
function observe(element, params){
clog('Observing dom change..');
// create an observer instance
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
var BreakException = {};
try{
mutations.forEach(function(mutation) {
// var $el = $(mutation.target);
// if( is_observed ) throw BreakException;
if ('function' == typeof params.callback)
params.callback( mutation.target );
});
}catch(e){
if (e!==BreakException) throw e;
}
});
// configuration of the observer:
var config = $.extend({
attributes: true,
childList: true,
characterData: true
}, params.config);
// pass in the target node, as well as the observer options
observer.observe(element, config);
// later, you can stop observing
// observer.disconnect();
gvar.observer = observer;
}
/**
* Igniter
*
* Here we initialize observing page has been loaded properly
* which identified with change in particular element.
*
* Dual method to watch using observer and interval of checking dom.
*/
(function init_observer(){
clog('init_observer..');
gvar.stIDomWatch = setInterval(function(){
let $wrap = $(gvar.root_player),
$img = null
;
if ($wrap.length){
$img = $wrap.find('#jp_poster_0');
if ($img.length)
gvar.thumbnail_link = $img.attr('src');
}
if (gvar.thumbnail_link){
clog('[OK] gvar.thumbnail_link found via stIDomWatch');
clog('gvar.thumbnail_link='+gvar.thumbnail_link);
clearInterval(gvar.stIDomWatch);
clog('Running main script..');
main();
}
}, 12);
})();
}
// main_script
setTimeout(function(){
var _$ = jQuery ? jQuery.noConflict():null;
if( _$ )
_$(function(){
main_script( _$ );
})
}, 123)
})();
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.