Permalink
Browse files

v0.7.2

  • Loading branch information...
1 parent 0c84144 commit 18cf20b38673c45c6a721da07356d90f8b3f3e32 @coronin committed Jan 2, 2012
Showing with 106 additions and 103 deletions.
  1. +1 −1 Info.plist
  2. +14 −42 Settings.plist
  3. BIN archive_old/thepaperlink-v072.safariextz
  4. +4 −8 content.js
  5. +87 −52 global.html
View
@@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
- <string>0.7.1</string>
+ <string>0.7.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>Chrome</key>
View
@@ -3,54 +3,22 @@
<plist version="1.0">
<array>
<dict>
+ <key>DefaultValue</key>
+ <true/>
<key>Key</key>
- <string>thepaperlink_apikey</string>
- <key>Password</key>
- <false/>
- <key>Secure</key>
- <false/>
- <key>Title</key>
- <string>the Paper Link access key</string>
- <key>Type</key>
- <string>TextField</string>
- </dict>
- <dict>
- <key>Type</key>
- <string>Separator</string>
- </dict>
- <dict>
- <key>Key</key>
- <string>pubmeder_email</string>
- <key>Secure</key>
- <false/>
- <key>Title</key>
- <string>pubmeder email</string>
- <key>Type</key>
- <string>TextField</string>
- </dict>
- <dict>
- <key>Key</key>
- <string>pubmeder_apikey</string>
- <key>Password</key>
- <false/>
- <key>Secure</key>
- <false/>
+ <string>tab_open_if_no_apikey</string>
<key>Title</key>
- <string>pubmeder apikey</string>
- <key>Type</key>
- <string>TextField</string>
- </dict>
- <dict>
+ <string>Obtain the access permission to personalized services</string>
<key>Type</key>
- <string>Separator</string>
+ <string>CheckBox</string>
</dict>
<dict>
<key>DefaultValue</key>
- <true/>
+ <false/>
<key>Key</key>
- <string>tab_open_if_no_apikey</string>
+ <string>no_context_menu</string>
<key>Title</key>
- <string>If the key is not valid, open related webpages to obtain</string>
+ <string>Do not shown the contextual menu (not ready)</string>
<key>Type</key>
<string>CheckBox</string>
</dict>
@@ -60,17 +28,21 @@
<key>Key</key>
<string>rev_proxy</string>
<key>Title</key>
- <string>Visit our reserse proxied site, for improved accessibility</string>
+ <string>Use our reserse proxied server (improved accessibility)</string>
<key>Type</key>
<string>CheckBox</string>
</dict>
<dict>
+ <key>Type</key>
+ <string>Separator</string>
+ </dict>
+ <dict>
<key>DefaultValue</key>
<string>http://a.b.c/d?url=</string>
<key>Key</key>
<string>ezproxy_prefix</string>
<key>Title</key>
- <string>Use ezproxy with prefix</string>
+ <string>Use ezproxy with prefix (be cautious)</string>
<key>Type</key>
<string>TextField</string>
</dict>
Binary file not shown.
View
@@ -89,7 +89,7 @@ function getPmid(zone, num) {
function get_Json(pmids) {
var i, div,
- need_insert = 1,
+ need_insert = true,
url = '/api?flash=yes&a=safari1&pmid=' + pmids,
loading_span = '<span style="font-weight:normal;font-style:italic"> fetching data from "the Paper Link"</span>&nbsp;&nbsp;<img src="https://pubget-hrd.appspot.com/static/loadingLine.gif" width="16" height="11" alt="loading" />';
if (search_term) {
@@ -101,7 +101,7 @@ function get_Json(pmids) {
if (t('h2')[i].className === 'result_count') {
old_title = t('h2')[i].innerHTML;
title_pos = i;
- need_insert = 0;
+ need_insert = false;
t('h2')[i].innerHTML = old_title + loading_span;
}
}
@@ -246,11 +246,7 @@ function gotMessage(msg) {
if (!$('paperlink2_display')) {
peaks = document.createElement('script');
peaks.setAttribute('type', 'text/javascript');
- if (base_uri === 'http://0.pl4.me') {
- peaks.setAttribute('src', 'http://0.pl4.me/jss?y=' + (Math.random()));
- } else {
- peaks.setAttribute('src', 'https://pubget-hrd.appspot.com/jss?y=' + (Math.random()));
- }
+ peaks.setAttribute('src', base_uri + '/jss?y=' + (Math.random()));
page_body.appendChild(peaks);
}
if (pubmeder) {
@@ -349,4 +345,4 @@ function gotMessage(msg) {
break;
}
}
-safari.self.addEventListener('message', gotMessage, false);
+safari.self.addEventListener('message', gotMessage, false);
View
@@ -11,7 +11,7 @@
function (xml) {
var pmid = $(xml).find('Id');
if (pmid.length === 1) {
- localStorage.setItem(pmid.text(), 20121230);
+ save_visited_ID( pmid.text() );
}
},
'xml'
@@ -83,13 +83,12 @@
// above, direct copy from Chrome
-
function saveApikeyToLocal(email, apikey) {
if (email) {
- safari.extension.settings.pubmeder_email = email;
- safari.extension.settings.pubmeder_apikey = apikey;
+ localStorage.setItem('pubmeder_email', email);
+ localStorage.setItem('pubmeder_apikey', apikey);
} else {
- safari.extension.settings.thepaperlink_apikey = apikey;
+ localStorage.setItem('thepaperlink_apikey', apikey);
}
}
@@ -104,16 +103,16 @@
}
function get_thepaperlink_json(url) {
- var apikey = safari.extension.settings.thepaperlink_apikey,
- pubmeder_apikey = safari.extension.settings.pubmeder_apikey,
- pubmeder_email = safari.extension.settings.pubmeder_email,
- pubmeder_ok = 0,
+ var apikey = localStorage.getItem('thepaperlink_apikey'),
+ pubmeder_apikey = localStorage.getItem('pubmeder_apikey'),
+ pubmeder_email = localStorage.getItem('pubmeder_email'),
+ pubmeder_ok = false,
p = safari.extension.settings.ezproxy_prefix || '',
oauth_status = safari.extension.settings.oauth_status || '',
cloud_op = '',
- base_uri;
- if ((pubmeder_apikey !== undefined) && (pubmeder_email !== undefined)) {
- pubmeder_ok = 1;
+ base_uri = 'https://pubget-hrd.appspot.com';
+ if (pubmeder_apikey && pubmeder_email) {
+ pubmeder_ok = true;
}
if (p === 'http://a.b.c/d?url=') {
p = '';
@@ -130,24 +129,18 @@
if (oauth_status.indexOf('douban') > -1) {
cloud_op += 'b';
}
- if (apikey === undefined) {
- apikey = 'G0oasfw0382Wd3oQ0l1LiWzE'; // temp apikey, may disabled in the future
+ var req_key = apikey;
+ if (!apikey) {
+ req_key = 'G0oasfw0382Wd3oQ0l1LiWzE'; // temp apikey, may disabled in the future
}
if (safari.extension.settings.rev_proxy) {
base_uri = 'http://0.pl4.me';
- } else {
- base_uri = 'https://pubget-hrd.appspot.com';
}
if (url) {
- $.getJSON(base_uri + url + apikey, function (d) {
+ $.getJSON(base_uri + url + req_key, function (d) {
if (d && (d.count || d.error)) { // good or bad, both got json return
- if (safari.extension.settings.thepaperlink_apikey) {
- safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('tj', [
- d, apikey, pubmeder_ok, pubmeder_apikey, pubmeder_email, cloud_op, base_uri, p ]);
- } else {
- safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('tj', [
- d, '', pubmeder_ok, pubmeder_apikey, pubmeder_email, cloud_op, base_uri, p ]);
- }
+ safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('tj', [
+ d, apikey, pubmeder_ok, pubmeder_apikey, pubmeder_email, cloud_op, base_uri, p ]);
} else {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('except', apikey);
}
@@ -176,6 +169,73 @@
} }
}
+function save_visited_ID(new_id) {
+ var id_found = localStorage.getItem('id_found');
+ if (id_found === null) {
+ localStorage.setItem('id_found', new_id);
+ } else if (id_found.indexOf(new_id) === -1) {
+ localStorage.setItem('id_found', id_found + ' ' + new_id);
+ }
+ if (id_found && id_found.split(' ').length > 11) {
+ saveIt_pubmeder( localStorage.getItem('id_found').replace(/\s+/g, ',') );
+ }
+}
+
+function saveIt_pubmeder(pmid) {
+ var args = {'apikey' : localStorage.getItem('pubmeder_apikey'),
+ 'email' : localStorage.getItem('pubmeder_email'),
+ 'pmid' : pmid},
+ url = 'https://pubmeder-hrd.appspot.com/input?callback=?';
+ if (args.apikey === null || args.email === null) {
+ console.log('no valid pubmeder credit, open related URL');
+ if (safari.extension.settings.tab_open_if_no_apikey) {
+ var tab = safari.application.activeBrowserWindow.openTab();
+ tab.url = 'http://www.pubmeder.com/registration';
+ }
+ return;
+ }
+ if (safari.extension.settings.rev_proxy) {
+ url = 'http://1.pl4.me/input?callback=?';
+ }
+ $.getJSON(url, args, function (d) {
+ if (d.respond > 1) {
+ if (localStorage.getItem('id_history') === null) {
+ localStorage.setItem('id_history', pmid);
+ } else {
+ var pre_history = localStorage.getItem('id_history');
+ localStorage.setItem('id_history', pre_history + ',' + pmid);
+ console.log(pre_history + ',' + pmid);
+ }
+ localStorage.setItem('id_found', '');
+ }
+ });
+}
+
+// -- Liang Cai, 2012 -- //
+
+if (safari.extension.settings.tab_open_if_no_apikey && (
+ localStorage.getItem('pubmeder_apikey') === null || localStorage.getItem('pubmeder_email') === null)) {
+ alert('to bookmark references into your personal account,\nplease generate the apikey at www.pubmeder.com');
+ var tab = safari.application.activeBrowserWindow.openTab();
+ tab.url = 'http://www.pubmeder.com/registration';
+}
+
+if (safari.extension.settings.tab_open_if_no_apikey && localStorage.getItem('thepaperlink_apikey') === null) {
+ alert('to accelerate your access speed to "the Paper Link",\nplease obtain your own apikey at www.thepaperlink.com');
+ var tab = safari.application.activeBrowserWindow.openTab();
+ tab.url = 'http://www.thepaperlink.com/reg';
+}
+
+$.ajax({
+ url: 'https://pubget-hrd.appspot.com/static/humans.txt',
+ dataType: 'text',
+ timeout: 4000,
+ success: function() { console.log('Hi, you can access our secured server directly.'); },
+ error: function() {
+ console.log('error? force rev_proxy');
+ safari.extension.settings.rev_proxy = true; }
+});
+
function handleMessage(msg) {
switch (msg.name) {
@@ -194,7 +254,7 @@
if (dotCheck.test(msg.message) || pmcCheck.test(msg.message)) {
eSearch(msg.message);
} else {
- localStorage.setItem(msg.message, 20121230);
+ save_visited_ID(msg.message);
}
break;
case 'upload_pdf':
@@ -205,7 +265,6 @@
}
safari.application.addEventListener('message', handleMessage, false);
-
function performCommand(event) {
if (event.command === 'visit-the-paper-link') {
var tab = safari.application.activeBrowserWindow.openTab();
@@ -216,8 +275,8 @@
}
} else if (event.command === 'find-id-on-the-page') {
var base,
- apikey = safari.extension.settings.thepaperlink_apikey;
- if (apikey === undefined) {
+ apikey = localStorage.getItem('thepaperlink_apikey');
+ if (apikey === null) {
apikey = 'G0oasfw0382Wd3oQ0l1LiWzE'; // temp apikey, may disabled in the future
}
if (safari.extension.settings.rev_proxy) {
@@ -231,7 +290,6 @@
}
safari.application.addEventListener('command', performCommand, false);
-
function doValidation(event) {
if (event.command === 'visit-the-paper-link' && event.userInfo) {
if (event.userInfo.length < 25) {
@@ -243,29 +301,6 @@
}
}
safari.application.addEventListener('validate', doValidation, false);
-
-
-if (safari.extension.settings.tab_open_if_no_apikey && (!safari.extension.settings.pubmeder_apikey || !safari.extension.settings.pubmeder_email)) {
- alert('to bookmark references into your personal account,\nplease generate the apikey at www.pubmeder.com');
- var tab = safari.application.activeBrowserWindow.openTab();
- tab.url = 'http://www.pubmeder.com/registration';
-}
-
-if (safari.extension.settings.tab_open_if_no_apikey && !safari.extension.settings.thepaperlink_apikey) {
- alert('to accelerate your access speed to "the Paper Link",\nplease obtain your own apikey at www.thepaperlink.com');
- var tab = safari.application.activeBrowserWindow.openTab();
- tab.url = 'http://www.thepaperlink.com/reg';
-}
-
-$.ajax({
- url: 'https://pubget-hrd.appspot.com/static/humans.txt',
- dataType: 'text',
- timeout: 4000,
- success: function() { console.log('Hi, you can access our secured server directly.'); },
- error: function() {
- console.log('error? force rev_proxy');
- safari.extension.settings.rev_proxy = true; }
-});
</script>
</head>
<body></body>

1 comment on commit 18cf20b

@coronin
Owner
coronin commented on 18cf20b Jan 2, 2012

united pubmeder with thepaperlink, for Apple Safari

Please sign in to comment.