vk.com

Layout Design - bigger video and thumbs and Info on precent video and some navigation

  1. /// ==UserScript==
  2. // @name vk.com
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 0.25
  5. // @description Layout Design - bigger video and thumbs and Info on precent video and some navigation
  6.  
  7. // @match *vk.com/*
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  9. // @require https://greasyfork.org/scripts/386-waituntilexists/code/waitUntilExists.js?version=5026
  10. // @require http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js
  11.  
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_deleteValue
  15.  
  16. // @created 2014-09-27
  17. // @released 2014-00-00
  18. // @updated 2014-00-00
  19. // @history @version 0.25 - first version: @released - 2015-02-11
  20.  
  21. // @compatible Greasemonkey, Tampermonkey
  22. // @license GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
  23. // @copyright 2014+, Magnus Fohlström
  24. // ==/UserScript==
  25.  
  26. /*global $, jQuery*/
  27. /*jshint -W014, -W030*/
  28. // -W014, laxbreak, Bad line breaking before '+'
  29. // -W030, Expected assignment or funtion call insted saw an expression
  30.  
  31. //-----------------------------------------------------------------------------------------------------------------------------------------
  32.  
  33. (function ($) {
  34. var timeThis = performance.now(),
  35. mainWidth = 1357,
  36. lstate = 0;
  37. function l( name, fn, showthis ){ if( showthis == 1 || lstate == showthis ) console.log( name, fn !== undefined ? fn : '' ); }
  38. String.prototype.formatString = function(){
  39. return this.toString()
  40. .split(/\s+/g).join(' ')
  41. .split('¤').join('')
  42. .split('{').join('{\n\t\t')
  43. .split('; ').join(';')
  44. .split(';').join(';\n\t\t')
  45. .split('*/').join('*/\n')
  46. .split('\t\t').join('\t')
  47. .split('}').join('}\n');
  48. };
  49. $( '<style id="InsertCssZoom"></style>' +
  50. '<style id="InsertCssBasic"></style>' +
  51. '<style id="inputPopupCss" ></style>' ).appendTo('head');
  52. function refreshElement( elem , speed ) //refreshElement('.videoPlayer','slow');
  53. {
  54. var data = $( elem ).html();
  55. $( elem ).hide().html( data ).fadeIn( speed );
  56. }
  57. function playerSize()
  58. {
  59. var sideWidth = 120,
  60. ContWidth = 1500,
  61. bodyWidth0 = window.innerWidth - sideWidth,
  62. bodyWidth1 = bodyWidth0 > ContWidth ? ContWidth : bodyWidth0,
  63. zoomWidth0 = bodyWidth1 / $('#video_player').width(),
  64. zoomWidth = zoomWidth0 < 1 ? 1 : zoomWidth0;
  65. $( '#InsertCssZoom' ).text( '#video_player { zoom:' + zoomWidth + '; }' );
  66. }
  67. function init(input)
  68. {
  69. var InsertCssBasic, insertReload, newWidth, divider, insertThis;
  70. insertReload =
  71. // '<div class="divider fl_r">|</div>' +
  72. '<div id="NormalizeThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="mv_top_button fl_r">Normalize</div>' +
  73. '<div id="MaximizeThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="mv_top_button fl_r">Maximize</div>' +
  74. '<div class="divider fl_r">|</div>' +
  75. '<div id="reloadThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="mv_top_button fl_r">Reload</div>' +
  76. '<div class="divider fl_r">|</div>' +
  77. '<div id="ChangeThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="mv_top_button fl_r">Change Title</div>';
  78. // $( insertReload ).appendTo('#mv_top_controls');
  79. // $( insertReload ).insertAfter('.mv_share_actions.fl_l .fl_r .mv_views_count.fl_r');
  80. insertThis = setInterval(function(){ $('.mv_info_block.fl_l').size() !== 0 && $('#NormalizeThis').size() === 0 && ( $( insertReload ).appendTo('.mv_info_block.fl_l'), clearInterval(insertThis) ); },8);
  81. divider = 4;
  82. newWidth = input !== undefined ? input : mainWidth;
  83. InsertCssBasic =
  84. '.mv_cont {'
  85. + ' top: 30px !important;'
  86. + ' }'
  87. + '#mv_box {'
  88. + ' background: #232430;'
  89. + ' }'
  90. + '.mv_top_button {'
  91. + ' background: transparent;'
  92. + ' color: rgb(119, 119, 119);'
  93. + ' margin-top: -4px;'
  94. + ' }'
  95. + '.video_box_wrap {'
  96. + ' width: initial !important;'
  97. + ' height: initial !important;'
  98. + ' }'
  99. + '#mv_min_layer {'
  100. + ' width: calc(100% - 250px);'
  101. + ' }'
  102. + '#mv_min_title {'
  103. + ' max-width: 100% !important;'
  104. + ' }'
  105. + '#mv_title {'
  106. + ' width: 100%;'
  107. + ' max-width: 100%;'
  108. + ' }'
  109. + '#mv_min_title:hover, .mv_top_button:hover {'
  110. + ' cursor: pointer;'
  111. + ' color: rgb(7, 7, 207) !important;'
  112. + ' }'
  113. + '.fl_r.mv_title_panel {'
  114. + ' width: calc(100% - 65px);'
  115. + ' }'
  116. + '.mv_info_block.fl_l {'
  117. + ' width: 100%;'
  118. + ' }'
  119. + '#page_layout {'
  120. + ' width: '+newWidth+'px !important;'
  121. + ' }'
  122. + '#page_body {'
  123. + ' width: calc(100% - 165px) !important;'
  124. + ' }'
  125. + '.video_compact_view #choose_video_rows .video_row, .video_compact_view #video_rows .video_row, '
  126. + '.video_compact_view #video_search_rows .video_row, .video_compact_view .search_media_rows.video_type .video_row {'
  127. + ' height: initial;'
  128. + ' margin-bottom: 20px;'
  129. + ' width: calc(('+newWidth+'px - 165px) / '+divider+' - 23px);'
  130. + ' }'
  131. + '.video_compact_view #choose_video_rows .video_row_thumb, .video_compact_view #video_rows .video_row_thumb, '
  132. + '.video_compact_view #video_search_rows .video_row_thumb, .video_compact_view .search_media_rows.video_type .video_row_thumb, '
  133. + '.video_compact_view #choose_video_rows .video_image_div, .video_compact_view .search_media_rows.video_type .video_image_div, '
  134. + '.video_compact_view #video_rows .video_image_div, .video_compact_view #video_search_rows .video_image_div {'
  135. + ' width: inherit;'
  136. + ' }'
  137. + '.video_compact_view #choose_video_rows .video_image_div, .video_compact_view #video_rows .video_image_div, '
  138. + '.video_compact_view #video_search_rows .video_image_div, .video_compact_view .search_media_rows.video_type .video_image_div, '
  139. + '.video_compact_view #choose_video_rows .video_row_thumb, .video_compact_view #video_rows .video_row_thumb, '
  140. + '.video_compact_view #video_search_rows .video_row_thumb, .video_compact_view .search_media_rows.video_type .video_row_thumb {'
  141. + ' height: calc((('+newWidth+'px - 165px) / '+divider+' - 23px) * (106/191));'
  142. + ' }'
  143. + '#search_content .video_row .video_row_info_name a, #video_content .video_row .video_row_info_name a, '
  144. + '#choose_video_content .video_row .video_row_info_name a, #pva_video_tags .video_row .video_row_info_name a {'
  145. + ' white-space: normal;'
  146. + ' overflow: hidden;'
  147. + ' text-overflow: ellipsis;'
  148. + ' width: calc(('+newWidth+'px - 165px) / '+divider+' - 23px) !important;'
  149. + ' display: -webkit-box;'
  150. + ' height: calc( 11px * 1.4 * 3 );'
  151. + ' font-size: 11px;'
  152. + ' line-height: 1.4;'
  153. + ' -webkit-line-clamp: 3;'
  154. + ' -webkit-box-orient: vertical;'
  155. + ' }';
  156. $( '#InsertCssBasic' ).html( InsertCssBasic.formatString() );
  157. $( '#InsertCssBasic' ).append( '#stl_side { left: '+( $( '#page_layout' ).offset().left )+'px !important; }'.formatString() );
  158. }
  159. init();
  160. $( window ).resize(function(){ init(); });
  161. $( '#NormalizeThis' ).waitUntilExists(function(){
  162. function Maximize()
  163. {
  164. GM_setValue('VK_playerState', 'Maximize' );
  165. playerSize();
  166. $(".mv_top_button:contains('Maximize')").hide();
  167. $(".mv_top_button:contains('Normalize')").show();
  168. }
  169. function Normalize()
  170. {
  171. GM_setValue('VK_playerState', 'Normalize' );
  172. $( '#InsertCssZoom' ).empty();
  173. $(".mv_top_button:contains('Normalize')").hide();
  174. $(".mv_top_button:contains('Maximize')").show();
  175. }
  176. GM_getValue('VK_playerState') == 'Maximize' ? Maximize() : Normalize();
  177. $("#NormalizeThis").on('click', Normalize );
  178. $("#MaximizeThis").on('click', Maximize );
  179. $('#reloadThis').on('click', function() {
  180. refreshElement('#mv_content .video_box_wrap', 2500 );
  181. });
  182. $('#ChangeThis, #ChangeThis font').on('mouseup', function(e){
  183. this == e.target && e.which == 1 && rewriteTitle();
  184. });
  185. });
  186. function runflashvars()
  187. {
  188. var flashvars,Seconds_1,Seconds,xformat,time;
  189. flashvars = $('embed').attr('flashvars');
  190. flashvars = flashvars !== undefined ? flashvars : '';
  191. Seconds_1 = flashvars.split('&duration=');
  192. Seconds = Seconds_1[1] === undefined ? '' : Seconds_1[1].split('&eid1=');
  193. Seconds = Seconds[0] === undefined ? 0 : Seconds[0];
  194. xformat = ( Seconds < 3600 ) ? 'mm:ss' : 'H:mm:ss';
  195. time = moment().startOf('day').seconds(Seconds).format(xformat);
  196. console.log('sec',Seconds);
  197. // Display how long the video clip are
  198. if( $('#VideoLength').size() === 0 )
  199. {
  200. $('<div id="VideoLength" class="mv_info mv_duration" style="margin-left: 20px;">Video Length:<span style="padding-left:22px;">' + time + '</span></div><br class="my"><div class="clear"></div>').insertAfter('.mv_info_panel.clear_fix');
  201. }
  202. // Show a list of Qualities that are playable for this clip
  203. window.qualities = '';
  204. function stp( qual,input ){ window.qualities += '<span class="mv_info mv_quality" style="float: none !important; margin-bottom: 10px;"><span>' + qual + '</span> - ' + input + '</span><br>'; }
  205. if ( flashvars.search('&url720=' ) > 0 ) { stp('720p','HD'); }
  206. if ( flashvars.search('&url480=' ) > 0 ) { stp('480p','SD'); }
  207. if ( flashvars.search('&url360=' ) > 0 ) { stp('360p','Normal'); }
  208. if ( flashvars.search('&url240=' ) > 0 ) { stp('240p','Almost'); }
  209. if ( flashvars.search('&url180=' ) > 0 ) { stp('180p','Lowest'); }
  210. $( '<div class="mv_info mv_quality_lable" style="margin-left: 20px; float:left;">Video Qualities:</div> <div class="mv_info mv_qualities" style="float:left; margin-left:15px;">' + window.qualities + '</div>' ).insertAfter('br.my');
  211. }
  212. $( '#video_player' ).waitUntilExists(function() { $( '#VideoLength' ).size() === 0 && runflashvars(); });
  213. // Re-sizing inputField
  214. function sizingInput( str )
  215. {
  216. str = str === undefined ? ' ' : str;
  217. var texLen = str.length,
  218. parLen = $('#toInputingThis').width() - 6,
  219. inputWidth = ( texLen * 5.2 ) + 21;
  220. // this makes sure that inputfield dont get bigger than avaible space
  221. inputWidth = inputWidth > parLen ? parLen : inputWidth;
  222. // check if string is longer than, then the field gets bigger, otherwise it vill stay the same as default.
  223. inputWidth = texLen > 34 ? inputWidth : 200;
  224. // makes the change as defined
  225. $( '#txtInputThis' ).width( inputWidth );
  226. }
  227. $( window ).resize(function() {
  228. playerSize();
  229. sizingInput( $( '#txtInputThis' ).val() );
  230. });
  231. // this is usefull when same page reloads, with new uniqe URL && only applicable within 10s from clicking reload.
  232. var mainTitleHead = '#mv_title',
  233. docLoc = window.location.href,
  234. lastUrl = GM_getValue('VK_lastUrl') === docLoc,
  235. ifReloaded = GM_getValue('VK_title_old') !== undefined && lastUrl;
  236. if( lastUrl && $.now() - GM_getValue('VK_date') < 10000 )
  237. {
  238. $( '#mv_title' ).waitUntilExists(function(){
  239. var changeTo = GM_getValue('VK_title');
  240. $( '#txtInputThis' ).val( changeTo );
  241. $( mainTitleHead + ', title').text( changeTo );
  242. });
  243. }
  244. function rewriteTitle()
  245. {
  246. function thePopup()
  247. {
  248. var inputPopup, inputPopupCss, thisTitle, author;
  249. inputPopup =
  250. '<div id="space"class="ymvy"></div>'
  251. + '<div class="divider fl_r">|</div>'
  252. + '<div id="CancelsNowThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Cancel</div>'
  253. + '<div class="divider fl_r">|</div>'
  254. + '<div id="SaveReloadThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Reload</div>'
  255. + '<div class="divider fl_r">|</div>'
  256. + '<div id="justupdateThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Update</div>'
  257. + '<div class="divider fl_r">|</div>'
  258. + '<div id="toInputingThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">'
  259. + '<input id="txtInputThis" type="text" class="" value=""/>'
  260. + '</div>'
  261. + '<div class="divider fl_r">|</div>'
  262. + '<div id="LatestTextThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Latest</div>'
  263. + '<div class="divider fl_r">|</div>'
  264. + '<div id="MostUseTxtThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Most</div>'
  265. + '<div class="divider fl_r">|</div>'
  266. + '<div id="FavoritTxtThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Favorits</div>'
  267. + '<div class="divider fl_r">|</div>'
  268. + '<div id="restsTextsThis" onmouseover="Videoview.activate(this, 2);" onmouseout="Videoview.deactivate(this, 2);" class="ymvy">Resets</div>'
  269. + '<div class="divider fl_r">|</div>'
  270. + ' ';
  271. inputPopupCss =
  272. '#inputPopup {'
  273. + ' width: calc(100% - 14px);'
  274. + ' background-color:#232430;'
  275. + ' position: fixed;'
  276. + ' z-index: 1000;'
  277. + ' height: 40px;'
  278. + ' margin:auto;'
  279. + ' top:0px;'
  280. + ' }'
  281. + '#space {'
  282. + ' width: 40px;'
  283. + ' }'
  284. + '.ymvy {'
  285. + ' float: right;'
  286. + ' color: #777777;'
  287. + ' cursor: pointer;'
  288. + ' padding: 12px 5px 12px;'
  289. + ' }'
  290. + '#toInputingThis {'
  291. + ' margin-top: -4px;'
  292. + ' width: calc(100% - (87px * 6) );'
  293. + ' }'
  294. + 'input#txtInputThis {'
  295. + ' width: 200px;'
  296. + ' padding-left: 3px;'
  297. + ' line-height: 15px;'
  298. + ' background-color: darkgray;'
  299. + ' }'
  300. + '#inputPopup .divider.fl_r {'
  301. + ' padding: 12px 5px;'
  302. + ' opacity: .5;'
  303. + ' }';
  304. $( '#inputPopupCss' ).html( inputPopupCss.formatString() );
  305. $('<div id="inputPopup" style="display:none;">' + inputPopup + '</div>').insertBefore('#mv_layer_wrap');
  306. author = $('.mv_author_name a').text();
  307. thisTitle = $( mainTitleHead ).text() + ( ifReloaded || ( mainTitleHead.search( author ) > -1 ) ? '' : ' - ' + author );
  308. if( ifReloaded )
  309. {
  310. $('#restsTextsThis').attr('data-thisTitle', GM_getValue('VK_title_old') );
  311. GM_deleteValue('VK_title_old');
  312. }
  313. else
  314. {
  315. $('#restsTextsThis').attr('data-thisTitle', thisTitle);
  316. }
  317. $('#txtInputThis').val( thisTitle );
  318. }
  319. function doThis()
  320. {
  321. $('#inputPopup').slideToggle( 1000 );
  322. }
  323. if( $('#inputPopup').size() < 1 )
  324. {
  325. thePopup();
  326. doThis();
  327. sizingInput( $( '#txtInputThis' ).val() );
  328. }
  329. else
  330. {
  331. doThis();
  332. }
  333. function handlestr( str )
  334. {
  335. var strArray = str.split(' ');
  336. }
  337. $('#CancelsNowThis').off().on('mousedown',function() {
  338. $('#inputPopup').slideUp( 1000 );
  339. });
  340. $('#SaveReloadThis').off().on('mousedown',function() {
  341. var NewurlThis,
  342. nowTime = $.now(),
  343. titleThis = $('#txtInputThis').val(),
  344. oldtitleThis = $('#restsTextsThis').attr('data-thisTitle'),
  345. urlThis = docLoc;
  346. // Stored so it can be checked and used later after page are reloaded.
  347. GM_setValue('VK_date', nowTime );
  348. GM_setValue('VK_title', titleThis );
  349. GM_setValue('VK_title_old', oldtitleThis );
  350. // Clean up earlier uniqe generated url
  351. if( urlThis.search('=ffff') > 0 )
  352. {
  353. NewurlThis = urlThis.split('=ffff');
  354. urlThis = NewurlThis[0].slice(0, -1 );
  355. }
  356. // Creat new uniqe generated url and store as value, so it can be check when page loads.
  357. // This needs to be done so that download button gets the new title
  358. urlThis = urlThis + '?=ffff' + nowTime;
  359. GM_setValue('VK_lastUrl', urlThis );
  360. // Reload with that newley created url.
  361. window.location.href = urlThis;
  362. });
  363. $('#justupdateThis').off().on('mousedown',function() {
  364. var changeTo = $('#txtInputThis').val();
  365. $( mainTitleHead + ', title').text( changeTo );
  366. });
  367. $('#restsTextsThis').off().on('mousedown',function() {
  368. var changeTo = $('#restsTextsThis').attr('data-thisTitle');
  369. sizingInput( changeTo );
  370. $('#txtInputThis').val( changeTo );
  371. $( mainTitleHead + ', title').text( changeTo );
  372. });
  373. $( '#txtInputThis' ).bind("input change paste keyup", function( target ) {
  374. sizingInput( target.currentTarget.value );
  375. });
  376. }
  377. $(document).on('click','*',function(e){ this == e.target && l('target',e.target,1); });
  378. console.log('timeThis', performance.now() - timeThis );
  379.  
  380. }(jQuery));
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.