gpt4 book ai didi

javascript - 获取脚本以返回 HTML 中的链接

转载 作者:行者123 更新时间:2023-12-03 12:11:59 24 4
gpt4 key购买 nike

我找到了一个用于从 Feedly 中提取已保存文章的脚本(通过在 Chrome 的 Inspect Element 控制台中运行它),但我想根据我的需要对其进行一些调整。我不是开发人员或类似人员,因此如果有人可以提供帮助,我将不胜感激!

这是脚本的一部分:

json = ""
function copyToClipboard() {
// Loop through the DOM, grabbing the information from each bookmark
map = jQuery("#section0_column0 div.u0Entry.quicklisted").map(function(i, el) {
var $el = jQuery(el);
var regex = /published:(.*)\ --/i;
return {
title: $el.data("title"),
url: $el.data("alternate-link"),
time: regex.exec($el.find("div.lastModified span").attr("title"))[1]
};
}).get(); // Convert jQuery object into an array

// Convert to a nicely indented JSON string
json = JSON.stringify(map, undefined, 2)

以下是它返回的示例:

[
{
"title": "Blog post headline",
"url": "http://urlofblogpost.com/article",
"time": "Tue, 10 Dec 2014 21:00:00 GMT"
},
{
"title": "Blog post2 headline",
"url": "http://urlofblogpost.com/article2",
"time": "Tue, 10 Dec 2014 21:00:00 GMT"
},
]

这是我希望它返回的内容:

<a href="http://urlofblogpost.com/article">Blog post headline</a>
<a href="http://urlofblogpost.com/article2">Blog post2 headline</a>

我自己能做的最多就是从脚本中删除“时间”部分,删除括号,并隔离标题和 URL(使用文本编辑器):

Blog post headline
http://urlofblogpost.com/article

有什么方法可以更改脚本以使其进入链接吗?

最佳答案

只需迭代 json:

Javascript:

function copyToClipboard() {
// Loop through the DOM, grabbing the information from each bookmark
map = jQuery("#section0_column0 div.u0Entry.quicklisted").map(function(i, el) {
var $el = jQuery(el);
var regex = /published:(.*)\ --/i;
return {
title: $el.data("title"),
url: $el.data("alternate-link"),
time: regex.exec($el.find("div.lastModified span").attr("title"))[1]
};
}).get(); // Convert jQuery object into an array

var theLink = '';
$.each(yourJson, function(k,v){
theLink += "<a href=" + v.url + " >" + v.title + " </a>, \n";
});

window.prompt('my link', theLink);

我创建了js fiddle 给你玩:http://jsfiddle.net/reptildarat/GG5BP/4/

关于javascript - 获取脚本以返回 HTML 中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24923888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com