본문으로 이동

사용자:Sijunpark/common.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

articlekit_iPad=navigator.platform=="iPad";articlekit_SupportsTouches="createTouch"in document;Element.prototype.hasClassName=function(a){return RegExp("(?:^|\\s+)"+a+"(?:\\s+|$)").test(this.className)};Element.prototype.addClassName=function(a){if(!this.hasClassName(a))this.className=[this.className,a].join(" ")};Element.prototype.removeClassName=function(a){if(this.hasClassName(a))this.className=this.className.replace(RegExp("(?:^|\\s+)"+a+"(?:\\s+|$)","g")," ")};
Element.prototype.toggleClassName=function(a){this[this.hasClassName(a)?"removeClassName":"addClassName"](a)};function parseUri(a){var b=parseUri.options;a=b.parser[b.strictMode?"strict":"loose"].exec(a);for(var c={},d=14;d--;)c[b.key[d]]=a[d]||"";c[b.q.name]={};c[b.key[12]].replace(b.q.parser,function(e,h,f){if(h)c[b.q.name][h]=f});return c}
parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
function AKRect(a,b,c,d){this.x=a;this.y=b;this.width=c;this.height=d}AKRect.prototype.getIntersection=function(a){var b=Math.max(this.x,a.x),c=Math.min(this.x+this.width,a.x+a.width);if(b<=c){var d=Math.max(this.y,a.y);a=Math.min(this.y+this.height,a.y+a.height);if(d<=a)return new AKRect(b,d,c-b,a-d)}return null};function hasClass(a,b){return a&&a.className.match(RegExp("(\\s|^)"+b+"(\\s|$)"))}function addClass(a,b){if(a)this.hasClass(a,b)||(a.className+=" "+b)}
function removeClass(a,b){if(hasClass(a,b))a.className=a.className.replace(RegExp("(\\s|^)"+b+"(\\s|$)")," ")}Array.prototype.foreach=function(a){for(var b=0;b<this.length;b++)a(b,this[b])};Object.prototype.foreach=function(a){for(var b in this)typeof this[b]!="function"&&a(b,this[b])};
Node.prototype.getParentOrSelfLink=function(){if(this.webkitMatchesSelector(":link")||this.hasAttribute("onclick")||hasClass(this,"table-cell"))return this;if(this.parentElement)return this.parentElement.getParentOrSelfLink();return null};Node.prototype.getFirstAncestorOrSelfWithTagName=function(a){if(this.tagName.toLowerCase()==a)return this;var b=this.parentElement;if(b)return b.getFirstAncestorOrSelfWithTagName(a);return null};
Node.prototype.getFirstAncestorOfClass=function(a){var b=this.parentElement;if(b)return hasClass(b,a)?b:b.getFirstAncestorOfClass(a);return null};Node.prototype.getFirstAncestorOrSelfOfClass=function(a){if(hasClass(this,a))return this;var b=this.parentElement;if(b)return b.getFirstAncestorOrSelfOfClass(a);return null};
Node.prototype.getFirstAncestorOrSelfMatchingSelector=function(a){if(this.webkitMatchesSelector(a))return this;var b=this.parentElement;if(b)return b.getFirstAncestorOrSelfMatchingSelector(a);return null};Node.prototype.getPreviousSiblingMatchingSelector=function(a){var b=this.previousElementSibling;if(b)return b.webkitMatchesSelector(a)?b:b.getPreviousSiblingNotMatchingSelector(a);return null};
Node.prototype.getPreviousSiblingNotMatchingSelector=function(a){var b=this.previousElementSibling;if(b)return b.webkitMatchesSelector(a)?b.getPreviousSiblingNotMatchingSelector(a):b;return null};function documentCoordinateToViewportCoordinate(a,b){var c={};c.x=a-window.pageXOffset;c.y=b-window.pageYOffset;return c}function viewportCoordinateToDocumentCoordinate(a,b){var c={};c.x=a+window.pageXOffset;c.y=b+window.pageYOffset;return c}
Document.prototype.elementFromPointIsUsingViewPortCoordinates=function(){if(window.pageYOffset>0)return this.elementFromPoint(0,window.pageYOffset+window.innerHeight-1)==null;else if(window.pageXOffset>0)return this.elementFromPoint(window.pageXOffset+window.innerWidth-1,0)==null;return false};
Document.prototype.elementFromDocumentPoint=function(a,b){if(this.elementFromPointIsUsingViewPortCoordinates()){var c=documentCoordinateToViewportCoordinate(a,b);return this.elementFromPoint(c.x,c.y)}else return this.elementFromPoint(a,b)};Document.prototype.elementFromViewportPoint=function(a,b){if(this.elementFromPointIsUsingViewPortCoordinates())return this.elementFromPoint(a,b);else{var c=viewportCoordinateToDocumentCoordinate(a,b);return this.elementFromPoint(c.x,c.y)}};
Document.prototype.getContentRectOffset=function(){if(document.webkitBuild<533.17)return new WebKitPoint(0,0);return new WebKitPoint(window.scrollX,window.scrollY)};Document.prototype.getLinkFromPoint=function(a,b){var c=document.elementFromViewportPoint(a,b);(c=c?c.getParentOrSelfLink():null)||(c=this.getLinkFromRect(a-11,b-11,22,22));return c};
Document.prototype.getLinkFromRect=function(a,b,c,d){var e=document.elementFromViewportPoint(a+c*0.5,b+d*0.5),h=null;if(e){h=e.getParentOrSelfLink();if(!h&&e!=document.documentElement&&e!=document.body){a=new AKRect(a,b,c,d);b=e.querySelectorAll(":link");for(c=0;c<b.length;++c){d=b[c];for(var f=d.getClientRects(),i=0;i<f.length;++i){var g=f[i];g=a.getIntersection(new AKRect(g.left,g.top,g.width,g.height));if(g!=null&&g.height>0)return d}}}}if(!h&&e)h=e.getFirstAncestorOrSelfOfClass("table-placeholder");
return h};function AKDocumentController(){this.chapterIndexVisible=false;this.highlighter=this.highlightedLink=null;var a=this;document.addEventListener("DOMContentLoaded",function(){a.restructureDocument();if(articlekit_SupportsTouches)document.location="x-articlekit-internal://documentDidLoad"},false);document.webkitBuild=this.getWebKitBuild()}AKDocumentController.prototype.getWebKitBuild=function(){var a=0,b=/WebKit\/([\d.]+)/.exec(navigator.userAgent);if(b)a=parseFloat(b[1]);return a};
AKDocumentController.prototype.adjustDocumentFontSize=function(){var a=parseUri(document.location);if(a&&a.queryKey)(a=a.queryKey.documentFontSize)&&addClass(document.body,a)};AKDocumentController.prototype.restructureDocument=function(){navigator.platform=="iPad"&&addClass(document.documentElement,"articlekit-ipad");this.restructureReferencesChapter();this.restructureImagePreviews();this.restructureTablePlaceholders();hasClass(document.body,"articlekit-tablesheet")&&this.restructureTableSheets()};
AKDocumentController.prototype.restructureImagePreviews=function(){for(var a=document.querySelectorAll(".thumb.center, .thumb.tnone, .thumb.tleft, .thumbnail-placeholder"),b=0;b<a.length;++b)this.restructureImagePreview(a[b])};
AKDocumentController.prototype.restructureImagePreview=function(a){if(a){a.hasAttribute("style")&&!hasClass(a,"thumbnail-placeholder")&&a.removeAttribute("style");for(var b=document.querySelectorAll("div[style], .thumbinner, .image, img"),c=0;c<b.length;++c){var d=b[c];d.removeAttribute("style");d.removeAttribute("width");d.removeAttribute("height")}if(a.webkitMatchesSelector(".center, .tnone, .tleft")){if((b=a.getPreviousSiblingNotMatchingSelector(".tleft, .tright, .tnone, .center, .floatleft, .floatright, .thumb, .image"))&&
b.webkitMatchesSelector("#jump-to-nav, .rellink, h1, h2, h3")){removeClass(a,"tleft");removeClass(a,"tnone");removeClass(a,"center");addClass(a,"tright")}if(a.getPreviousSiblingMatchingSelector(".tright, .floatright")||a.getFirstAncestorOfClass("tright")){removeClass(a,"tleft");removeClass(a,"tnone");removeClass(a,"center");addClass(a,"tright")}}var e=this;(b=a.querySelector("img"))||(b=a.getParentOrSelfLink());b||(b=a);b.onclick=null;b.addEventListener("click",function(h){h=h.target.getParentOrSelfLink();
h=e.getLinkMetadata(h);document.location="x-articlekit-internal://presentItem?metadata="+encodeURIComponent(h)},true)}};AKDocumentController.prototype.restructureTablePlaceholders=function(){for(var a=document.querySelectorAll(".table-placeholder"),b=0;b<a.length;++b)this.restructureTablePlaceholder(a[b])};
AKDocumentController.prototype.restructureTablePlaceholder=function(a){if(a){var b=this;a.addEventListener("click",function(c){var d=c.target.getParentOrSelfLink();d||(d=c.target.getFirstAncestorOrSelfOfClass("table-placeholder"));if(d){c=encodeURIComponent(b.getLinkMetadata(d));d="x-articlekit-internal://presentItem";if(c)d+="?metadata="+c;document.location=d}},false)}};
AKDocumentController.prototype.restructureReferencesChapter=function(){for(var a=document.querySelectorAll(".reference"),b=0;b<a.length;++b){var c=a[b];c.parentNode.removeChild(c)}a=document.querySelectorAll(".references");for(b=0;b<a.length;++b){for(c=c=a[b];c.parentNode&&c.parentNode.id!="bodyContent"&&!hasClass(c.parentNode,"mw-content-ltr")&&!hasClass(c.parentNode,"mw-content-rtl");)c=c.parentNode;var d=c?c.previousElementSibling:null,e=null;if(d&&(hasClass(d,"metadata")||hasClass(d,"noprint|portal"))){e=
d;d=e.previousElementSibling}if(d&&d.tagName=="H2"){addClass(d,"hidden");addClass(c,"hidden");addClass(e,"hidden")}}};AKDocumentController.prototype.restructureTableSheets=function(){for(var a=document.querySelectorAll(".articlekit-tablesheet > table .fn, .articlekit-tablesheet > table th.summary"),b=0;b<a.length;++b){var c=a[b].getFirstAncestorOrSelfWithTagName("tr");c&&c.parentNode.removeChild(c)}};
AKDocumentController.prototype.getMetadataForLinkAtPoint=function(a,b){var c=document.getLinkFromPoint(a,b);if(c)return this.getLinkMetadata(c);return null};
AKDocumentController.prototype.getLinkMetadata=function(a){if(a){var b=a.getFirstAncestorOrSelfOfClass("article-summary");if(b)return this.getSummaryMetadata(b,a);if(hasClass(a,"image"))return this.getImageMetadata(a);if(hasClass(a,"external|ext|extiw"))return this.getExternalLinkMetadata(a);if(hasClass(a,"table-cell"))return this.getTableCellMetadata(a);return this.getArticleLinkMetadata(a)}return null};
AKDocumentController.prototype.getArticleLinkMetadata=function(a){var b={};b.type="regular";b.URL=a.href;b.rects=this.getClientRectStrings(a);b.readLater=this.getReadLaterMetadata(a);return JSON.stringify(b)};AKDocumentController.prototype.getExternalLinkMetadata=function(a){var b={};b.type="external";b.URL=a.href;b.rects=this.getClientRectStrings(a);return JSON.stringify(b)};AKDocumentController.prototype.getTableCellMetadata=function(a){var b={};b.type="table-cell";b.URL=a.href;b.id=a.id;return JSON.stringify(b)};
AKDocumentController.prototype.getSummaryMetadata=function(a,b){var c={};c.type="table-cell";c.URL=b.href;c.id=a.id;return JSON.stringify(c)};
AKDocumentController.prototype.getImageMetadata=function(a){var b=a.querySelector("img"),c=b.getBoundingClientRect(),d=parseFloat(window.getComputedStyle(b,null).getPropertyValue("border-left-width")),e=parseFloat(window.getComputedStyle(b,null).getPropertyValue("border-top-width")),h=parseFloat(window.getComputedStyle(b,null).getPropertyValue("border-right-width")),f=parseFloat(window.getComputedStyle(b,null).getPropertyValue("border-bottom-width")),i=this.getImageID(a),g={};g.type="image";var j=
document.getContentRectOffset();g.boundingRect="{{"+(c.left+j.x)+","+(c.top+j.y)+"},{"+c.width+","+c.height+"}}";g.rect="{{"+(c.left+d+j.x)+","+(c.top+e+j.y)+"},{"+(c.width-d-h)+","+(c.height-e-f)+"}}";g.URL=a.href;g.previewURL=b.src;g.id=i;g.caption=this.getImagePreviewCaption(i);return JSON.stringify(g)};AKDocumentController.prototype.getImageID=function(a){if(a.hasAttribute("id"))if(a.id.match("^AKImage")=="AKImage")return a.id;if(a=a.parentNode)return this.getImageID(a);return null};
AKDocumentController.prototype.getReadLaterMetadata=function(a){var b=document.getSelection();b.removeAllRanges();var c=document.createRange();c.selectNodeContents(a);b.addRange(c);b.modify("extend","backward","sentence");var d=b.getRangeAt(0),e=c.toString(),h=null;h=document.webkitBuild>=534.46&&document.webkitBuild<536.26?d.toString().length:d.toString().length-e.length;b.modify("extend","forward","sentence");var f=b.getRangeAt(0);c.setStart(d.startContainer,d.startOffset);c.setEnd(f.endContainer,
f.endOffset);a.getFirstAncestorOrSelfWithTagName("li")!=null&&c.setEndBefore(f.endContainer);d=this.getClientRectStrings(c);f=this.getBoundingClientRectString(c);b.removeAllRanges();a=a.getFirstAncestorOrSelfMatchingSelector(".thumbcaption, tr");if(a!=null){f=this.getBoundingClientRectString(a);d=[f]}a={};a.boundingRect=f;a.rects=d;a.text=c.toString();a.targetTextRange="{"+h+", "+e.length+"}";return a};
AKDocumentController.prototype.getChapterIndexMetadata=function(){for(var a=document.querySelectorAll("h2"),b=[],c=0;c<a.length;++c){var d=a[c],e={};if(d.id.length==0)d.id="articlekit-chapter-"+c;e.id=d.id;e.tag=d.tagName;e.offset=d.offsetTop;b.push(e)}return JSON.stringify(b)};
AKDocumentController.prototype.getClientRectStrings=function(a){a=a.getClientRects();for(var b=[],c=document.getContentRectOffset(),d=0;d<a.length;++d){var e=a[d];b.push("{{"+(e.left+c.x)+","+(e.top+c.y)+"},{"+e.width+","+e.height+"}}")}return b};AKDocumentController.prototype.getBoundingClientRectString=function(a){a=a.getBoundingClientRect();var b=document.getContentRectOffset();return"{{"+(a.left+b.x)+","+(a.top+b.y)+"},{"+a.width+","+a.height+"}}"};
AKDocumentController.prototype.getImagePreviewCaption=function(a){if(!a)return"";a=document.getElementById(a);var b=a.querySelector(".thumbcaption");if(!b){var c=a.getFirstAncestorOrSelfOfClass("thumbinner");if(c)b=c.querySelector(".thumbcaption")}if(b)return this.getTextForNode(b);if(a=a.getFirstAncestorOrSelfOfClass("gallerybox"))if(a=a.querySelector(".gallerytext"))return this.getTextForNode(a);return""};
AKDocumentController.prototype.setImagePreview=function(a,b,c){var d=this,e=new Image,h=function(){var f=document.getElementById(a),i=d.getImageElementFromHTML(c),g=i.querySelector("img[src='"+a+"']");g||(g=i);if(g)g.src=b;if(f&&f.parentNode){f.parentNode.replaceChild(i,f);d.restructureImagePreview(i)}if(g){f=document.createElement("span");f.className="ak-image-background userSelectionDisabled userInteractionDisabled";i=window.getComputedStyle(g,null);f.style.width=i.getPropertyValue("width");f.style.height=
i.getPropertyValue("height");g.parentElement.appendChild(f)}};e.onload=function(){window.setTimeout(h,0.125)};e.src=b;e.complete&&window.setTimeout(h,0.125)};AKDocumentController.prototype.getImageElementFromHTML=function(a){var b=document.createElement("span");b.innerHTML=a;if(b.childNodes.length==0)return null;return b.childNodes[0]};AKDocumentController.prototype.getTextForNode=function(a){var b=document.createRange();b.selectNodeContents(a);return b.toString()};
AKDocumentController.prototype.getSelectedText=function(){return window.getSelection().toString()};AKDocumentController.prototype.getSelectedHTML=function(){var a=window.getSelection();if(a.rangeCount>0){a=a.getRangeAt(0).cloneContents();for(var b=a.querySelectorAll("img[articlekit_src]"),c=0;c<b.length;++c){var d=b[c];d.src=d.getAttribute("articlekit_src")}a=a.childNodes;b="";for(c=0;c<a.length;++c){d=a[c];b+=d.outerHTML?d.outerHTML:d.textContent}return b}return null};
AKDocumentController.prototype.presentFontSizeBezel=function(a){if(a.scale>1.25)document.location="x-articlekit-internal://increaseFontSize";else if(a.scale<=0.75)document.location="x-articlekit-internal://decreaseFontSize"};var articleKitDocumentController=new AKDocumentController;