Browse Source

replace "favorite" bookmarklet

Twitter changed some XSS security settings which prevents Quill from injecting JS onto the page for the inline "favorite" button. This change makes it open the "favorite" screen in a new window.
pull/25/head
Aaron Parecki 8 years ago
parent
commit
6083000764
3 changed files with 21 additions and 15 deletions
  1. +18
    -4
      views/new-favorite.php
  2. +0
    -1
      views/partials/bookmark-bookmarklet.php
  3. +3
    -10
      views/partials/favorite-bookmarklet.php

+ 18
- 4
views/new-favorite.php View File

@ -22,7 +22,7 @@
<div style="clear: both;"></div> <div style="clear: both;"></div>
<hr> <hr>
<div style="text-align: right;">
<div style="text-align: right;" id="bookmarklet">
Bookmarklet: <a href="javascript:<?= js_bookmarklet('partials/favorite-bookmarklet', $this) ?>" class="btn btn-default btn-xs">favorite</a> Bookmarklet: <a href="javascript:<?= js_bookmarklet('partials/favorite-bookmarklet', $this) ?>" class="btn btn-default btn-xs">favorite</a>
</div> </div>
@ -31,6 +31,12 @@
<script> <script>
$(function(){ $(function(){
var autosubmit = window.location.search.match('autosubmit=true');
if(autosubmit) {
$(".footer, #bookmarklet").hide();
}
// ctrl-s to save // ctrl-s to save
$(window).on('keydown', function(e){ $(window).on('keydown', function(e){
if(e.keyCode == 83 && e.ctrlKey){ if(e.keyCode == 83 && e.ctrlKey){
@ -52,9 +58,13 @@ $(function(){
if(response.location != false) { if(response.location != false) {
$("#test_success").removeClass('hidden');
$("#test_error").addClass('hidden');
$("#post_href").attr("href", response.location);
if(autosubmit) {
$("#btn_post").hide();
} else {
$("#test_success").removeClass('hidden');
$("#test_error").addClass('hidden');
$("#post_href").attr("href", response.location);
}
window.location = response.location; window.location = response.location;
} else { } else {
@ -66,6 +76,10 @@ $(function(){
return false; return false;
}); });
if(autosubmit) {
$("#btn_post").click();
}
bind_syndication_buttons(); bind_syndication_buttons();
}); });

+ 0
- 1
views/partials/bookmark-bookmarklet.php View File

@ -2,4 +2,3 @@
var t;try{t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));}catch(e){t="";}; var t;try{t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));}catch(e){t="";};
window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>"; window.location="<?= Config::$base_url ?>bookmark?url="+encodeURIComponent(window.location.href)+"&content="+encodeURIComponent((t == '' ? '' : '"'+t+'"'))+"&name="+encodeURIComponent(document.title)+"&token=<?= $this->token ?>";
})(); })();

+ 3
- 10
views/partials/favorite-bookmarklet.php View File

@ -1,10 +1,3 @@
var quill_popup=function(){
window.open(document.getElementById('quill-script').src.replace('favorite.js?','favorite-popup?'),'quill-like', 'status=no,directories=no,location=no,resizable=no,menubar=no,width=300,height=200,toolbar=no');
};
(function(){
var quill=document.createElement('script');
quill.src='<?= Config::$base_url ?>favorite.js?url='+encodeURIComponent(window.location)+'&token=<?= $this->token ?>';
quill.setAttribute('id','quill-script');
quill.setAttribute('onerror', 'quill_popup()');
document.body.appendChild(quill);
})();
(function(){
window.open("<?= Config::$base_url ?>favorite?url="+encodeURIComponent(window.location.href)+"&autosubmit=true&token=<?= $this->token ?>");
})();

Loading…
Cancel
Save