Orareview Helper

Help you making life easier when orareview.

目前為 2014-07-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Orareview Helper
// @namespace
// @version    0.1
// @description  Help you making life easier when orareview.
// @match      https://orareview.us.oracle.com/*
// @require    https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant      unsafeWindow
// @copyright  2014, Rex
// @namespace https://greasyfork.org/users/3729
// ==/UserScript==

(function(document,jQuery) {
    var $=jQuery;
    var patternPageMap={"onMainPage":/\.com\/\d+$/g, "onDiffPage":/\.com\/\d+\/diff[2]?\/\d+(:\d+)?\/\d+/g};
    
    var paramLineWidth='display_width',patternLineWidth=new RegExp(paramLineWidth);
    var preferedLineWidth=80;
    function log(){
      unsafeWindow.console.debug.apply(unsafeWindow.console,arguments);   
    }
    function getPreferedLineWidth(){
        var lineNumberColWidth=0, codeViewportWidth=0, windowWidth=jQuery(unsafeWindow).width();
        if(!!jQuery('table#table-top').length){
            codeViewportWidth=jQuery('table#table-top').width();
            jQuery('table#thecode:first tbody tr:eq(1) b').each(function(i,col){
                lineNumberColWidth=jQuery(col).width();
            });
        }
        if(lineNumberColWidth==0){
            lineNumberColWidth=42;
            if(codeViewportWidth==0){
             	codeViewportWidth=windowWidth-26;
            }
        }
        return parseInt(((codeViewportWidth-lineNumberColWidth*2)/2)/7);
    }
    function onDiffPage(){
        //log('onDiffPage');
        var patternMatch=false,lineContent=null,filter=null;
        var lineFilters=[{name:"CreationDate",pattern:/<CreationDate>/g},{name:"LastUpdateDate",pattern:/<LastUpdateDate>/g},{name:"LastUpdateLogin",pattern:/<LastUpdateLogin>/g}];/**['<CreationDate>','<LastUpdateDate>','<LastUpdateLogin>','<BaseFlowParameterId>'];*/
        jQuery("table#thecode tbody tr[id*=pair]:has(td[class*=replace])").each(function(i,tr){
          tr=jQuery(tr);
          lineContent=tr.text();
          patternMatch=false;
          for(i in lineFilters){
              filter=lineFilters[i];
            if(filter && filter.pattern && filter.pattern.test(lineContent)){
                //log(lineContent, filter.pattern, tr);
                patternMatch=true;
                break;
            }
          }
          if(patternMatch){tr.toggle();}else{//remove spaces only changes TOCONFIG
              var diffsInline=tr.find("[class*=dark]");
              if(!jQuery.trim(diffsInline.text()).length){
                  if(diffsInline.parents("td:first").index()==0)
                  	  diffsInline.addClass('oldequal');
                  else
                      diffsInline.addClass('newequal');
              }
          }
        });///**
        //remain current display width when jumping to another file
        var fileJumper=jQuery('select[onChange*=M_jumpToPatch]:first');
        var displayWidth=parseInt(jQuery(":input[name="+paramLineWidth+"]:visible:first").val());
        
        fileJumper.children().each(function(i,opt){
            if(i==0 && patternLineWidth.test(opt.value)){
                return false;
            }else if(i==0){
                if(isNaN(displayWidth) || displayWidth==80){
                	displayWidth=getPreferedLineWidth();
            	}   
            }
          opt.value+='?display_width='+displayWidth;
        });//*/
    }
    function onMainPage(){
        //change default line width of orareview diff page
        //log('onMainPage');
        var diffLink = null;
        var paramName=paramLineWidth, adjustedParamValue = preferedLineWidth?preferedLineWidth:105, paramRegExp = new RegExp(paramName+'=(\d*)');
        jQuery('a[href*=diff]').each(function(i,a){
          a=jQuery(a);
          diffLink = a.attr('href');
          if(/^\/\d+\/diff[2]?\/\d+(:\d+)?\/\d+$/.test(diffLink)){
            if(!/\?/.test(diffLink)){diffLink+='?';}else{
                if(!/\?$/.test(diffLink)){
                    diffLink+='&';
                }
            }
            if(paramRegExp.test(diffLink)){
                diffLink=diffLink.replace(paramRegExp,paramName+'='+adjustedParamValue);
            }else{
                diffLink+=paramName+'='+adjustedParamValue;
            }
            a.attr('href',diffLink);
          }
        });
    }
    function main(){
        log('Orareview Helper loaded.');
        unsafeWindow.jQuery=jQuery;
        preferedLineWidth=getPreferedLineWidth();
        var documentLocation = document.location.href;
        //log('preferedLW',preferedLineWidth,'documentLocation',documentLocation);
        var pattern=null;
        for(fnd in patternPageMap){
            pattern=patternPageMap[fnd];
            if(pattern.test(documentLocation)){
                log(fnd,pattern);
            	eval(fnd+'.apply()');
                break;
            }
        }
    }
	main();
})(window.document,jQuery);