Greasy Fork

Greasy Fork is available in English.

Orareview Helper

Help you making life easier when orareview.

当前为 2014-07-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 http://greasyfork.icu/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);