Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cardlink

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardlink

为页面上的超链接生成卡片式链接 | Generate card-based links for hyperlinks on the page

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by450%
Maintainers
1
Weekly downloads
 
Created
Source
Language: English 中文

Generate card-based links for hyperlinks on the page

Version visitor_badge MIT License

Installation

Using npm:

npm install cardlink --save

Using CDN:

<script src="https://cdn.jsdelivr.net/npm/cardlink"></script>

<!-- Only use parseer -->
<script src="https://cdn.jsdelivr.net/npm/cardlink/dist/parse.js"></script>
<script>
  /**
   * Get info
   * @param {String} html String type html
   * @param {String} link Website address
   * @returns {{ title: string; link: string; icon: string }} Website info
   */
  cardLinkParse(html, link)
<script>

Usage

Modules

import cardLink from 'cardlink' // or const cardLink = require('cardlink')

// Only use parseer
import cardLinkParse from 'cardlink/parse' // or const cardLinkParse = require('cardlink/parse')

Browser

  1. Usage
<script>
  cardLink(document.querySelectorAll('article a[target=_blank]'))
</script>
  1. Usage
<script>
  // Set the cardlink property for the specified a tag, and finally call cardLink()
  document.querySelectorAll('article a[target=_blank]').forEach((el) => {
    el.setAttribute('cardlink', '')
  })

  // OR
  document.querySelector('a#example').setAttribute('cardlink', '')

  // By default, card links are generated for all `a[cardlink]` on the page
  cardLink()
</script>

Problems

Since this is a front-end request for HTML, some sites may have cross-domain (CORS) issues, so cardLink allows you to use a proxy server to request HTML from the target site

<script>
  // Note: cardLink sends requests to the proxy server only when cross-domain requests occur (thus reducing the pressure on the proxy server)
  // Preset the proxy server before executing cardLink
  cardLink.server = 'https://api.allorigins.win/raw?url='

  cardLink(document.querySelectorAll('article a[target=_blank]'))
</script>

Options API

cardLink(nodes)

Type: NodeList

default: document.querySelectorAll('a[cardlink]')

By default, card links are generated for all a[cardlink] on the page

Design Sketch

card-link

Keywords

FAQs

Package last updated on 11 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc