@future-scholars/paperlib-citation-count-extension
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,1 +0,1 @@ | ||
"use strict";var m=Object.defineProperty;var P=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e)=>m(i,"name",{value:e,configurable:!0});var u=(i,e,t)=>(P(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("fs");require("path");const g=class g{constructor({id:e,defaultPreference:t}){u(this,"id");u(this,"defaultPreference");this.id=e,this.checkPreference(t),this.defaultPreference=t}checkPreference(e){if(typeof e!="object")throw new Error("Preference must be a dict");for(const t in e){if(!e[t].type||!["string","boolean","options","pathpicker"].includes(e[t].type))throw new Error(`Preference ${t} has wrong type ${e[t].type}`);if(!e[t].name)throw new Error(`Preference ${t} has no name`);if(!e[t].description)throw new Error(`Preference ${t} has no description`);if(e[t].value===void 0||e[t].value===null)throw new Error(`Preference ${t} has no default value`);if(e[t].type==="options"&&!e[t].options)throw new Error(`Preference ${t} has no options`)}}};l(g,"PLExtension");let p=g;const S=l(({str:i,removeNewline:e=!1,removeWhite:t=!1,removeSymbol:a=!1,removeStr:n=null,lowercased:o=!1,trimWhite:s=!1,whiteSymbol:c=!1})=>{if(!i)return"";let r=i;return r?(n&&(r=r.replaceAll(n,"")),e&&(r=r.replace(/(\r\n|\n|\r)/gm,"")),s&&(r=r.trim()),t&&(r=r.replace(/\s/g,"")),a&&(r=r.replace(/[^\p{L}|\s]/gu,"")),o&&(r=r.toLowerCase()),c&&(r=r.replace(/[^\p{L}]/gu," ")),r):""},"formatString"),f={formatString:S};function v(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}l(v,"getDefaultExportFromCjs");var y={compareTwoStrings:w,findBestMatch:A};function w(i,e){if(i=i.replace(/\s+/g,""),e=e.replace(/\s+/g,""),i===e)return 1;if(i.length<2||e.length<2)return 0;let t=new Map;for(let n=0;n<i.length-1;n++){const o=i.substring(n,n+2),s=t.has(o)?t.get(o)+1:1;t.set(o,s)}let a=0;for(let n=0;n<e.length-1;n++){const o=e.substring(n,n+2),s=t.has(o)?t.get(o):0;s>0&&(t.set(o,s-1),a++)}return 2*a/(i.length+e.length-2)}l(w,"compareTwoStrings");function A(i,e){if(!$(i,e))throw new Error("Bad arguments: First argument should be a string, second should be an array of strings");const t=[];let a=0;for(let o=0;o<e.length;o++){const s=e[o],c=w(i,s);t.push({target:s,rating:c}),c>t[a].rating&&(a=o)}const n=t[a];return{ratings:t,bestMatch:n,bestMatchIndex:a}}l(A,"findBestMatch");function $(i,e){return!(typeof i!="string"||!Array.isArray(e)||!e.length||e.find(function(t){return typeof t!="string"}))}l($,"areArgsValid");const L=v(y),d=class d extends p{constructor(){super({id:"@future-scholars/paperlib-citation-count-extension",defaultPreference:{}});u(this,"disposeCallbacks");this.disposeCallbacks=[]}async initialize(){await PLExtAPI.extensionPreferenceService.register(this.id,this.defaultPreference),this.disposeCallbacks.push(PLAPI.uiStateService.onChanged("selectedPaperEntities",t=>{t.value.length===1&&this.getCitationCount(t.value[0])}))}async dispose(){for(const t of this.disposeCallbacks)t();PLExtAPI.extensionPreferenceService.unregister(this.id)}async getCitationCount(t){await PLAPI.uiSlotService.updateSlot("paperDetailsPanelSlot1",{"paperlib-citation-count":{title:"Citation Count",content:"N/A (N/A)"}});let a;t.doi!==""?a=`https://api.paperlib.app/metadata/citationcount?doi=${t.doi}`:t.arxiv!==""?a=`https://api.paperlib.app/metadata/citationcount?arxiv=${t.arxiv.toLowerCase().replace("arxiv:","").split("v")[0]}`:a=`https://api.paperlib.app/metadata/citationcount?title=${f.formatString({str:t.title,whiteSymbol:!0})}`;try{const o=(await PLExtAPI.networkTool.get(a,{},1,5e3,!0,!0)).body,s={semanticscholarId:"",citationCount:"N/A",influentialCitationCount:"N/A"};let c;o.data?c=o.data:c=[o];for(const r of c){const C=f.formatString({str:r.title,removeStr:"&",removeSymbol:!0,lowercased:!0}),b=f.formatString({str:t.title,removeStr:"&",removeSymbol:!0,lowercased:!0});if(L.compareTwoStrings(C,b)>.95){s.citationCount=`${r.citationCount}`,s.influentialCitationCount=`${r.influentialCitationCount}`;break}}PLAPI.uiSlotService.updateSlot("paperDetailsPanelSlot1",{"paperlib-citation-count":{title:"Citation Count",content:`${s.citationCount} (${s.influentialCitationCount})`}})}catch(n){if(n.message.includes("404")){PLAPI.logService.warn("Citation count not found.","",!1,"CitationCountExt");return}PLAPI.logService.error("Failed to get citation count.",n,!1,"CitationCountExt")}}};l(d,"PaperlibCitationCountExtension");let h=d;async function k(){const i=new h;return await i.initialize(),i}l(k,"initialize");exports.initialize=k; | ||
"use strict";var P=Object.defineProperty;var v=(i,e,t)=>e in i?P(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e)=>P(i,"name",{value:e,configurable:!0});var u=(i,e,t)=>(v(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("fs");require("path");const m=class m{constructor({id:e,defaultPreference:t}){u(this,"id");u(this,"defaultPreference");this.id=e,this.checkPreference(t),this.defaultPreference=t}checkPreference(e){if(typeof e!="object")throw new Error("Preference must be a dict");for(const t in e){if(!e[t].type||!["string","boolean","options","pathpicker","hidden"].includes(e[t].type))throw new Error(`Preference ${t} has wrong type ${e[t].type}`);if(!e[t].name)throw new Error(`Preference ${t} has no name`);if(!e[t].description)throw new Error(`Preference ${t} has no description`);if(e[t].value===void 0||e[t].value===null)throw new Error(`Preference ${t} has no default value`);if(e[t].type==="options"&&!e[t].options)throw new Error(`Preference ${t} has no options`)}}};l(m,"PLExtension");let h=m;const y=l(({str:i,removeNewline:e=!1,removeWhite:t=!1,removeSymbol:s=!1,removeStr:a=null,lowercased:n=!1,trimWhite:o=!1,whiteSymbol:c=!1})=>{if(!i)return"";let r=i;return r?(a&&(r=r.replaceAll(a,"")),e&&(r=r.replace(/(\r\n|\n|\r)/gm,"")),o&&(r=r.trim()),t&&(r=r.replace(/\s/g,"")),s&&(r=r.replace(/[^\p{L}|\s]/gu,"")),n&&(r=r.toLowerCase()),c&&(r=r.replace(/[^\p{L}]/gu," ")),r):""},"formatString");process.platform;const g={formatString:y};function A(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}l(A,"getDefaultExportFromCjs");var L={compareTwoStrings:b,findBestMatch:$};function b(i,e){if(i=i.replace(/\s+/g,""),e=e.replace(/\s+/g,""),i===e)return 1;if(i.length<2||e.length<2)return 0;let t=new Map;for(let a=0;a<i.length-1;a++){const n=i.substring(a,a+2),o=t.has(n)?t.get(n)+1:1;t.set(n,o)}let s=0;for(let a=0;a<e.length-1;a++){const n=e.substring(a,a+2),o=t.has(n)?t.get(n):0;o>0&&(t.set(n,o-1),s++)}return 2*s/(i.length+e.length-2)}l(b,"compareTwoStrings");function $(i,e){if(!I(i,e))throw new Error("Bad arguments: First argument should be a string, second should be an array of strings");const t=[];let s=0;for(let n=0;n<e.length;n++){const o=e[n],c=b(i,o);t.push({target:o,rating:c}),c>t[s].rating&&(s=n)}const a=t[s];return{ratings:t,bestMatch:a,bestMatchIndex:s}}l($,"findBestMatch");function I(i,e){return!(typeof i!="string"||!Array.isArray(e)||!e.length||e.find(function(t){return typeof t!="string"}))}l(I,"areArgsValid");const k=A(L),w=class w extends h{constructor(){super({id:"@future-scholars/paperlib-citation-count-extension",defaultPreference:{}});u(this,"disposeCallbacks");this.disposeCallbacks=[]}async initialize(){await PLExtAPI.extensionPreferenceService.register(this.id,this.defaultPreference),this.disposeCallbacks.push(PLAPI.uiStateService.onChanged("selectedPaperEntities",t=>{t.value.length===1&&this.getCitationCount(t.value[0])}))}async dispose(){for(const t of this.disposeCallbacks)t();PLExtAPI.extensionPreferenceService.unregister(this.id)}async getCitationCount(t){const a=await PLAPI.preferenceService.get("language")==="zh-CN"?"引用次数":"Citation Count";await PLAPI.uiSlotService.updateSlot("paperDetailsPanelSlot1",{"paperlib-citation-count":{title:a,content:"N/A (N/A)"}});let n;t.doi!==""?n=`https://api.paperlib.app/metadata/citationcount?doi=${t.doi}`:t.arxiv!==""?n=`https://api.paperlib.app/metadata/citationcount?arxiv=${t.arxiv.toLowerCase().replace("arxiv:","").split("v")[0]}`:n=`https://api.paperlib.app/metadata/citationcount?title=${g.formatString({str:t.title,whiteSymbol:!0})}`;try{const c=(await PLExtAPI.networkTool.get(n,{},1,5e3,!0,!0)).body,r={semanticscholarId:"",citationCount:"N/A",influentialCitationCount:"N/A"};let f;c.data?f=c.data:f=[c];for(const p of f){const C=g.formatString({str:p.title,removeStr:"&",removeSymbol:!0,lowercased:!0}),S=g.formatString({str:t.title,removeStr:"&",removeSymbol:!0,lowercased:!0});if(k.compareTwoStrings(C,S)>.95){r.citationCount=`${p.citationCount}`,r.influentialCitationCount=`${p.influentialCitationCount}`;break}}PLAPI.uiSlotService.updateSlot("paperDetailsPanelSlot1",{"paperlib-citation-count":{title:a,content:`${r.citationCount} (${r.influentialCitationCount})`}})}catch(o){if(o.message.includes("404")){PLAPI.logService.warn("Citation count not found.","",!1,"CitationCountExt");return}PLAPI.logService.error("Failed to get citation count.",o,!1,"CitationCountExt")}}};l(w,"PaperlibCitationCountExtension");let d=w;async function x(){const i=new d;return await i.initialize(),i}l(x,"initialize");exports.initialize=x; |
{ | ||
"name": "@future-scholars/paperlib-citation-count-extension", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Paperlib", | ||
@@ -20,3 +20,3 @@ "description": "Show the citation count in the detail panel.", | ||
"@types/node": "16.18.1", | ||
"paperlib-api": "^0.1.2", | ||
"paperlib-api": "^0.1.7", | ||
"prettier": "^3.1.1", | ||
@@ -23,0 +23,0 @@ "prettier-plugin-organize-imports": "^3.2.4", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5556