Skip to content

Commit

Permalink
Gist-raw-links: Fix clicking on raw urls. See #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed May 20, 2017
1 parent 68128fc commit ee1f778
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions gist-raw-links.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Gist Raw Links
// @version 0.1.0
// @version 0.1.1
// @description Add a button that contains a list of gist raw file links
// @license MIT
// @author Rob Garrison
Expand Down Expand Up @@ -35,7 +35,7 @@
<div class="dropdown-menu-content">
<ul class="dropdown-menu dropdown-menu-sw ghrl-files">
<div>
<img class="dots" src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif" width="32" alt="">
<img src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif" width="32" alt="">
</div>
</ul>
</div>`;
Expand Down Expand Up @@ -73,7 +73,6 @@
return false;
}
if (json && json.files) {
console.log(link);
addList(link, json.files);
}
}
Expand All @@ -84,9 +83,11 @@
function addList(link, files) {
let html = "";
Object.keys(files).forEach(file => {
html += `<a class="dropdown-item" href="${files[file].raw_url}">${file}</a>`;
html += `
<a class="dropdown-item ghrl-file" href="${files[file].raw_url}">
${file}
</a>`;
});
console.log('updating list', link);
$(".ghrl-files", link.parentNode).innerHTML = html;
}

Expand Down Expand Up @@ -120,6 +121,16 @@
el.addEventListener("click", removeBackdrop);
}
}, 100);
} else if (
target.classList.contains("ghrl-file") &&
// left mouse click only
event.button === 0 &&
// check for keyboard modifier + left click - the browser handles these
// clicks differently
!(event.shiftKey || event.ctrlKey || event.metaKey)
) {
// allow left click to pass through
window.location.href = target.href;
}
}, false);
}
Expand Down

0 comments on commit ee1f778

Please sign in to comment.