Virtonomica: "Обзор рынка лицензий: Спрос" и "Итоги торгов лицензиями"

выделяет технологии изученные вами, а так же добавляет кнопку продажи лицензий в итоги торгов лицензиями

当前为 2016-03-20 提交的版本,查看 最新版本

// ==UserScript==
// @name           Virtonomica: "Обзор рынка лицензий: Спрос" и "Итоги торгов лицензиями"
// @namespace      virtonomica
// @version 	   1.6
// @description    выделяет технологии изученные вами, а так же добавляет кнопку продажи лицензий в итоги торгов лицензиями	
// @include        http://*virtonomic*.*/*/main/globalreport/technology/*/*/target_market_summary
// @include        http://*virtonomic*.*/*/main/globalreport/technology/*/*/target_market_summary/*
// @include        http://*virtonomic*.*/*/main/management_action/*/investigations/technologies
// @include        http://*virtonomic*.*/*/main/globalreport/technology_target_market/total
// ==/UserScript==

var run = function() {

    var win = (typeof(unsafeWindow) != 'undefined' ? unsafeWindow : top.window);
    $ = win.$;

	function getVal(spName){
		return JSON.parse(window.localStorage.getItem(spName));
	}
	function setVal(spName, pValue){
		window.localStorage.setItem(spName, JSON.stringify(pValue));
	}
    function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
    }
    function getLvl(str) {
        var first = str.indexOf('</') + 4;
        var perc = trim(str.substr(0, first));

        var second = str.substr(first+1).indexOf('</') + 4;
        //var lvl = parseFloat(trim(str.substr(first+1, second)).replace("<b>","").replace("</b>",""), 10);
        var matches = str.substr(first+1, second).match(/([0-9]+\.[0-9]+)/);
        var lvl;
        if(matches == null || matches.length == 0){
            lvl = 0;
        }else{
            lvl =  parseFloat(matches[1], 10);
        }
        // console.log("'"+ lvl+"'" );
        return lvl;
    }
    function sort_table(tbody, col, asc){
        var rows = tbody.rows;
        var rlen = rows.length;
        var arr = [];
        var i, j, cells;
        // fill the array with values from the table
        for(i = 0; i < rlen; i++){
            cells = rows[i].cells;
            arr.push([rows[i], cells[col].innerHTML]);
        }
        // sort the array by the specified column number (col) and order (asc)
        arr.sort(function(a, b){
            return asc*compareSpec(a[1], b[1]);
        });
        for(i = 0; i < rlen; i++){
            tbody.appendChild(arr[i][0]);
        }
    }
	function getCurrDate(){
		return new Date().getDate();
	}
    function setTechList(callback) {
		var stab = getVal('techList');
		//console.log(Object.keys(stab).length);
		if (stab == null || stab['update_date'] != getCurrDate() || Object.keys(stab).length == 1) {
			stab = {};
			// получение информации о своих изученных технах	
			var tmurl=$( 'ul.#menutop a:contains("Предприятия")').attr('href').slice(0,-10);
			var numpos=tmurl.indexOf("company");
			var tmurl0=tmurl.substring(numpos+12); // 
			tmurl=tmurl.substring(0,numpos); // 
			tmurl=tmurl+"management_action"+tmurl0+"/investigations/technologies";

			$.get(tmurl,function(data){
				$('div[class="tech_row"] > div > div > a', data).each(function(){
					var link = $(this);
					//http://virtonomica.ru/olga/window/management_action/4207337/investigations/technology_offer_create/5/370088
					var matches = link.attr('href').match(/technology_offer_create\/(\d+)\/(\d+)/);
					var nteh = matches[1];
					var techId = matches[2];
					//console.log(link.attr('href'));
					stab[techId + '|' + nteh] = 1;
				});
				stab['update_date'] = getCurrDate();
				setVal('techList', stab);
				//alert(stab);
				if(callback != null) {
					callback();
				}
			});
		} else {
			if(callback != null) {
				callback();
			}
		}
	}
	function sortTable(){
		var rows = $('table[class="list"] > tbody > tr:has(td):has(a)');
		//console.log(rows.length);
		var path = '> td[style="background: rgb(154, 255, 154);"]';
		rows.sort(function(a, b) {
			//console.log($(path, a).length +' > '+ $(path, b).length);
			return $(path, b).length - $(path, a).length;
		});
		rows.each(function() {
        	var row = $(this);
			$('table[class="list"] > tbody:last-child').append(row);
		});
	}
	function set_color_teh() {
		var stab = getVal('techList');

		$('table[class="list"] > tbody > tr > td > a').each( function() {
        	var link = $(this);
			var href = link.attr('href');
			var matches = href.match(/technology\/(\d+)\/(\d+)\//);
			var techId = matches[1];
			var nteh = matches[2];
			//console.log(techId+'|'+nteh);
			// названия техн совпали
			var exist = stab[techId+'|'+nteh];
			if (exist != null && exist == 1)  {
				link.parent().css('background','#9AFF9A');
			}
		});
		sortTable();
	}
	function addSellLicenseLink() {
		var stab = getVal('techList');
		//http://virtonomica.ru/olga/main/globalreport/technology/380082/2/target_market_summary
		var svHref = window.location.href;
		var matches = svHref.match(/technology\/(\d+)\/(\d+)\//);
		var techId = matches[1];
		var nteh = matches[2];
		var exist = stab[techId+'|'+nteh];
		if (exist != null && exist == 1)  {
			//http://virtonomica.ru/olga/main/globalreport/technology/422577/2/target_market_summary/2015-05-01/bid
			//http://virtonomica.ru/olga/window/technology_market/bid/4207337/422577/5/set
			//http://virtonomica.ru/olga/main/company/view/4207337/dashboard
			matches = $('a[class="dashboard"]').attr('href').match(/([0-9]+)/);
			var companyId = matches[1];
			var svSellHref = svHref.replace('main/globalreport/technology/','window/technology_market/bid/'+companyId+'/').replace(/\/target_market_summary(\/\d+-\d+-\d+\/\w+)?/,'/set');
			var svSellLink = '<b><a href="'+svSellHref+'" onclick="return doWindow(this, 1000, 800);">Продать лицензии</a></b>';
			//http://virtonomica.ru/olga/main/management_action/4207337/technology_target_market/technologies
			var svOpenListHref = svHref.replace(/\/globalreport\/technology\/\w+\/\w+\/target_market_summary(\/\d+-\d+-\d+\/\w+)?/,'/management_action/'+companyId+'/technology_target_market/technologies');
			var svOpenListLink = '<b><a href="'+svOpenListHref+'" target="_blank">Список лицензий</a></b>';
			$('table[class="list"] > tbody > tr:last').after('<tr><td colspan="2">'+svSellLink+'</td><td colspan="3">'+svOpenListLink+'</td></tr>');
		}
	}
    //
    if (/http:\/\/\w*virtonomic\w+.\w+\/\w+\/main\/globalreport\/technology_target_market\/total/.test(window.location)) {
		setTechList(set_color_teh);
		var link = null;
		$('table[class="list"] > tbody > tr > td > a').each(function(){
        	link = $(this);
			link.attr('href', link.attr('href')+'/ask');
			link.attr('onclick', 'return doWindow(this, 1000, 600);');
			//console.log(link.attr('href'));
		});
	}
    if (/http:\/\/\w*virtonomic\w+.\w+\/\w+\/main\/globalreport\/technology\/\w+\/\w+\/target_market_summary/.test(window.location)
		||/http:\/\/\w*virtonomic\w+.\w+\/\w+\/main\/globalreport\/technology\/\w+\/\w+\/target_market_summary\/\w+\/\w+/.test(window.location)
		) {
		setTechList(addSellLicenseLink);
	}
}

if(window.top == window) {
    var script = document.createElement("script");
    script.textContent = '(' + run.toString() + ')();';
    document.documentElement.appendChild(script);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址